Search code examples
c++exceptiongdbg++abort

How to turn all throws into abort conditions for debugging purposes?


In a non-trivial program, there may be any number of exceptions, being thrown and caught. While this is intended to prevent crashes, it makes debugging harder (I debug with gdb) since I don't get to see the point (and its backtrace) where the exception was thrown when debugging the binary unless I identify the line and introduce a break point.

So, to facilitate analysis, it would be useful to tell g++ (or gdb?) to consider all throws as critical errors, similar to assertion failures. Is this at all possible without hacking the code?


Solution

  • It's trivial. The command is catch throw. Start gdb pointing it at your executable. Issue the catch throw command and then the run command.