Exception Handling
Windows’ SEH can be handled with compiler extension __try {} __exception() {} or by setting top-level handler via SetUnhandledExceptionFilter(). The latter is tricky since it’s easy to replace a previous registered handler whenever a module or library wants to.
Breakpad
Breakpad implements ExceptionHandler for Windows. It registers an exception handler that capable of dump minidump to a specified directory. It uses, unfortunately, SetUnhandledExceptionFilter() and potentially fail to capture an exception if another handler was registered after Breakpad.
Solution
We are left with __try {} __exception() {} as follows.
using namespace google_breakpad;
auto handler = ExceptionHandler(L"dumps", nullptr, nullptr, nullptr,
ExceptionHandler::HANDLER_NONE);
__try {
// ...
} __except(
(handler.WriteMinidumpForException(::GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
) {}
Note that GetExceptionInformation() is avail only in filter expression of __except(filter expression).
References
Breakpad repository
MSDN
Examples
Written with StackEdit.
留言
張貼留言