Search code examples
c++cgdb

GDB. Catch only not caught exceptions


Catching like this, using GDB:

catch throw

When exception is thrown, the program stops.

How to make GDB not stop when exception is thrown but is caught by the program ? Or should I have global try-catch and not using GDB

catch throw

?

EDIT1

try
{
  // every time exception is thrown
  // program is stopped by GDB
}
catch(const std::exception &e)
{
  // even if the exception is caught by the program
}

EDIT2 starting gdb

gdb
file /usr/home/user/program
shell ps x
attach #pid
catch throw
c

Solution

  • catch throw will catch all thrown exceptions and there isn't a way to restrict that.

    You have at least two options here. You could just not use catch throw at all, and if you're on some flavor of unix, it will seg fault and stop at the point the exception is thrown, if it won't be caught.

    Alternately you could set a breakpoint on __raise_exception as seen at ftp://ftp.gnu.org/pub/old-gnu/Manuals/gdb/html_node/gdb_30.html (which was the first hit when I used google - please try to research yourself before posting on Stackoverflow).