gdb - Prevent losing backtrace in a catch/rethrow situation
c++, exception, gdb
Solution
needing a back trace from the original throw of the exception,
Is it OK to use a simple approach of printing all backtraces of all throws and then when it is necessary to find a backtrace of a particular exception just find it by the address of the exception. Something like this sequence of gdb commands:
set pagination off
catch throw
commands
info args
bt
c
end
When you need to find backtrace of an exception, first print its address, like this:
print &exception
And find its address in the gdb output. It must be printed by `info args`. As soon as you find address there will be backtrace of this exception after `info args` output.
Problem
Is it possible to re-throw an exception without losing the back-trace in gdb? Or is there a way in gdb to "back up' a few lines and back trace from there? I'm on GDB 7.7.1, the most recent. I sometimes find myself running into situations like this, needing a back trace from the original throw of the exception, and needing to comment out the try/catch parts, recompiling, and re-running in gdb. ``` try { someFuncThatCanThrowException(); } catch(exceptionType& exception) { if(@CAN_RECOVER@) { ... } else { throw; } } ``` ----OR---- ``` try { someFuncThatCanThrowException(); } catch(exceptionType& exception) { exception.printMessageToCout(); throw; } ```