24

I am debugging code with exception throwing and exception handling. I would like gdb to break immediately when an exception is thrown, so i can inspect the state of the program and the call stack. How can I make gdb break when any exception is thrown?

zr.
  • 7,528
  • 11
  • 50
  • 84

1 Answers1

34

You can do this with the catch throw command. See here:

catch event

Stop when event occurs. The event can be any of the following:

throw [regexp]

rethrow [regexp]

catch [regexp]

The throwing, re-throwing, or catching of a C++ exception.

If regexp is given, then only exceptions whose type matches the regular expression will be caught.

Daniel Hershcovich
  • 3,751
  • 2
  • 30
  • 35