How do I get the value and type of the current exception in C++ using gdb?

Matt Joiner picture Matt Joiner · May 1, 2013 · Viewed 12.4k times · Source

gdb allows one to catch exceptions when they're thrown, and when they're caught. But sometimes the line an exception is thrown has no symbols, or a breakpoint is triggered during exception handling. How do I inspect the value of the current exception?

Answer

Tom Tromey picture Tom Tromey · Oct 20, 2015

Earlier answers were correct when written (in 2013), but since then gdb and libstdc++ have changed.

libstdc++ now has some hooks that let gdb interact more nicely with the exception system. In particular, there is now enough information exposed for gdb to provide a $_exception convenience variable to the user. This variable holds the exception being thrown. It is only valid at exactly the spot where the exception is being caught; which you can stop at using catch catch.

See the page from the manual for details.