If an exception is thrown in a C++ program control is either transferred to the exception handler or terminate()
is called.
Even if the program emits some diagnostics from inside the handler (or from terminate()
handler) that can be too late - the most value is in the call stack at the point where the exception is thrown, not in the handler.
On Windows a call stack can be obtained using [StackWalk64()
]1 function. The key is how to call that function at the right moment.
Is there a way to make a Visual C++ program execute some user code each time an exception (or an exception for which no handler is set) is thrown?