Calling UnhandledExceptionFilter Yourself

[Previous] [Next]

The UnhandledExceptionFilter function is a fully documented Windows function that you can call directly from within your own code. Here is an example of how you can use it:

 void Funcadelic() { _ _try {  } _ _except (ExpFltr(GetExceptionInformation())) {  } } LONG ExpFltr(PEXCEPTION_POINTERS pEP) { DWORD dwExceptionCode = pEP->ExceptionRecord.ExceptionCode; if (dwExceptionCode == EXCEPTION_ACCESS_VIOLATION) { // Do some work here.... return(EXCEPTION_CONTINUE_EXECUTION); } return(UnhandledExceptionFilter(pEP)); } 

In the Funcadelic function, an exception in the try block causes the ExpFltr function to be called. The ExpFltr function is passed the return value from GetExceptionInformation. Inside the exception filter, the exception code is determined and compared with EXCEPTION_ACCESS_VIOLATION. If an access violation has occurred, the exception filter corrects the situation and returns EXCEPTION_CONTINUE_EXECUTION from the filter. The return value causes the system to continue execution at the instruction that originally caused the exception in the first place.

If any other exception has occurred, ExpFltr calls UnhandledExceptionFilter, passing it the address of the EXCEPTION_POINTERS structure. UnhandledExceptionFilter then displays a message box that allows you to terminate the process or to begin debugging the process. The return value from UnhandledExceptionFilter is returned from ExpFltr.



Programming Applications for Microsoft Windows
Programming Applications for Microsoft Windows (Microsoft Programming Series)
ISBN: 1572319968
EAN: 2147483647
Year: 1999
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net