I would like too see the stacktrace after the exception is thrown of course using debugger. Normally, when the exception is never caught, the debugger stops the program after receiving SIGABRT
and I can see the whole stack trace and recognize the reason for the exception.
However how to diagnose the cause of the exception after catching it?
#include <iostream>
#include <stdexcept>
void foo() {
throw std::runtime_error("An error message");
}
int main() {
try {
foo();
} catch (const std::exception &e) {
std::cerr << e.what(); // add breakpoint here
}
return 0;
}
Adding a breakpoint in the catch section naturally stops the program after catching exception however the stack trace doesn't contain foo()
call therefore the cause of the exception cannot be diagnosed.
Please note that the example is really minimal and simple. With complex and nested calls the information that exception occurred somewhere in the try
section is virtually useless. And I cannot simply avoid catching exception because if I don't catch it then it is caught by the framework I'm using and the stacktrace is lost.