I have a Visual Studio 2008 C++ program where the program is wrapped in a __try
/__except
block to capture any SEH exceptions. The exception filter creates an error log and gives the user detailed instructions on how to submit a defect report.
Does the code within the filter need to be wrapped in another __try
/__except
block? If not, what happens if it excepts? If so, how should that be handled?
static int MyFilter( struct _EXCEPTION_POINTERS* ep )
{
/*
Code to log the exception information, and instruct the user
on how to submit a defect report. Should this be in another
__try/__except block?
*/
return EXCEPTION_EXECUTE_HANDLER;
}
int WINAPI _tWinMain( HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/,
LPTSTR lpstrCmdLine,
int nCmdShow )
{
int result = 0;
__try
{
result = Execute( hInstance, lpstrCmdLine, nCmdShow );
}
__except( MyFilter( GetExceptionInformation() ) )
{
// empty
}
return 0;
}
Thanks, PaulH
Edit:
If MyFilter
raises an exception, then I get in to an infinite exception loop. So, it looks like it does need __try
/__except
handling. I'm looking at doing this:
static int MyFilter( struct _EXCEPTION_POINTERS* ep )
{
__try
{
/*
Code to log the exception information, and instruct the user
on how to submit a defect report.
*/
// cause an exception
int x = 0, y = 1 / x;
}
__except( EXCEPTION_EXECUTE_HANDLER ) { /*empty*/ }
return EXCEPTION_EXECUTE_HANDLER;
}
In this case, the program should have an abnormal termination and exception should be passed up to the OS for it to deal with. Is that correct?