6

Normally I would leave it unhandled and the debugger (gdb, Eclipse CDT) would show me the call stack. Unfortunately the code is being called by a third party library which absorbs all exceptions. I can catch the exception before the third party library however I cannot see the call stack (stack-unwinding?).

How can I figure out where the exception was thrown?

Ali
  • 56,466
  • 29
  • 168
  • 265

2 Answers2

6

Would catchpoints help? You can break whenever an exception is thrown by entering the catch throw command in gdb. In Eclipse, you can do this through the gdb console. See this question.

Fred Larson
  • 60,987
  • 18
  • 112
  • 174
  • Upvote and thanks! Yes, in this particular case they helped :) But for the future: can I filter according to the type of exception? The third party library uses exceptions to flow control... so I would get too many notifications about exceptions being thrown. – Ali Jul 06 '11 at 22:25
  • @Ali: Sorry, what I know is in the link. I don't have any actual experience with this. I don't see a way to specify the exception type. – Fred Larson Jul 06 '11 at 22:27
  • 1
    I would like to accept your answer but please add more info for the general audience what to do (type catch throw in the gdb console) and this link: http://stackoverflow.com/q/1109922/341970 – Ali Jul 06 '11 at 22:30
4

You can put a breakpoint in the constructor for the exception object. Since this occurs before the exception is thrown, you get great visibility into the calling code.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • Upvoted and thanks! I cannot filter exceptions with the gdb catch throw solution, however, putting a breakpoint where out_of_range is thrown pretty much solves the problem. – Ali Jul 07 '11 at 14:44