I can tell the gdb debugger to stop as soon as any C++ exception is thrown by setting a catchpoint with the gdb command
catch throw
However, is there any way to only stop at uncaught C++ exceptions (like in C# or Java)? This would make it much easier to find bugs in some situations.
Thanks!
If an exception is uncaught, the special library function terminate()
is automatically called. Terminate is actually a pointer to a function and default value is the Standard C library function abort()
. You may be able to set a breakpoint on the call to the abort()
function and identify the location of the uncaught exception from there.
break abort
...
run
...
bt
You can install your own terminate()
function by using std::set_terminate()
. You should be able to set a breakpoint on your terminate function in gdb. You may be able to generate a stack backtrace from your terminate()
function and this backtrace may help in identifying the location of the exception. Additional details are provided here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With