I have a Visual Studio 2008 C++ Windows Mobile 6.5 project where I would like to catch SEH exceptions, write them to a file, and present the user with specific instructions on how to log a defect report for this issue. My code looks pretty much like this:
static int WriteDump( struct _EXCEPTION_POINTERS* ep )
{
// code to write info to a file
return EXCEPTION_EXECUTE_HANDLER;
}
int WINAPI _tWinMain( HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/,
LPTSTR lpstrCmdLine,
int nCmdShow )
{
int result = 0;
__try
{
result = StartMyGuiApp( hInstance, lpstrCmdLine, nCmdShow );
}
__except( WriteDump( GetExceptionInformation() ) )
{
// empty
}
return 0;
}
This works fine if the SEH exception is thrown from the main thread. But, if there is an exception in the GUI code (e.g. the WM_CREATE handler) then the usual “We’re Sorry…” dialog appears and my error handling code never executes.
What can I do to capture those exceptions? In C# .NET CF, I would subscribe to Application.ThreadException and Application.CurrentDomain.UnhandledException. for this. Is there a C++ equivalent?
Thanks,
PaulH
The window procedure is typically invoked indirectly and the library probably protects itself by inserting an SEH exception block around callback functions, masking the error and preventing it from propagating up the call stack and back to
WinMain().Add an SEH exception block in your window procedure to catch any exceptions occurring in your event handlers.