the problem of SEH
-
Hi! Once I used "SetUnhandledExceptionFilter()" function to set my own exception filter function.Then I could turn to the filter function when the exception occured.But the problem was that I could not get the exception information(EXCEPTION_RECORD).I wanted to use "GetExceptionInformation()" to get it,but the compiler prompted:'_exception_info' : bad context for intrinsic function',I could not understand it,why? Thanks!
-
Hi! Once I used "SetUnhandledExceptionFilter()" function to set my own exception filter function.Then I could turn to the filter function when the exception occured.But the problem was that I could not get the exception information(EXCEPTION_RECORD).I wanted to use "GetExceptionInformation()" to get it,but the compiler prompted:'_exception_info' : bad context for intrinsic function',I could not understand it,why? Thanks!
The function
GetExceptionInformation
can only be used in the context of an__except
block. An easy way to use structured exceptions is to define an SE handler using the C run-time function_set_se_translator()
. The CRT takes care of wiring everything together for you, so you don't have to worry aboutSetUnhandledExceptionFilter
etc. You can even avoid__try/__except
blocks by throwing a C++ exception. Brad -
The function
GetExceptionInformation
can only be used in the context of an__except
block. An easy way to use structured exceptions is to define an SE handler using the C run-time function_set_se_translator()
. The CRT takes care of wiring everything together for you, so you don't have to worry aboutSetUnhandledExceptionFilter
etc. You can even avoid__try/__except
blocks by throwing a C++ exception. BradBrad Sokol: Your solution is good! Thanks very much! Now I can do it well. On the other hand,I have another idea in my exception function,I want to get more information about the locale of exception,such as the information of the stack,like the vc++'s debug tools! Thanks!
-
Brad Sokol: Your solution is good! Thanks very much! Now I can do it well. On the other hand,I have another idea in my exception function,I want to get more information about the locale of exception,such as the information of the stack,like the vc++'s debug tools! Thanks!
Getting a stack trace including source file and line number is possible in both debug and release builds. The key is the
EXCEPTION_POINTERS
parameter. You need to use the symbols engine API which is in the dbghelp.dll library in the Platform SDK to translate the exception pointers into more useful information. The best reference I've found for this is "Debugging Windows Applications" by John Robbins. He used to write the Bug Slayer column in MSDN magazine. You can find lots of his archived articles over at the href='http://msdn.microsoft.com'>MSDN site. There is probably lots of useful stuff elswhere on the web but I don't have any links handy. Google for StackWalk or "win32 stack trace" and you'll probably find some useful links. HTH Brad