Unhandled exceptions can be caught and handled in C++ using the SetUnhandledExceptionFilter function.
This function allows you to set a custom exception handler that will be called when an unhandled exception occurs.
This can be useful for logging or reporting exceptions, or for performing cleanup operations before the program exits.
Main exception handler
Exception Filtering
To prevent the exception handler from being called recursively, or to prevent the exception handler from being called again if it throws an exception, you can use a spin-wait exception handler.
Writing a crash dump
When putting this into practice, you may want to write a minidump file when an unhandled exception occurs.
This can be done using the MiniDumpWriteDump function.
Demonstrating of how these functions can be used together, along with reporting the exception through the Windows Error Reporting API can be found in WERCrashApp.