Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy SetUnhandledExceptionFilter cannot capture some exception but AddVectoredExceptionHandler can do
    text
    copied!<p>I have experienced a problem that the function I passed to the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680634%28v=vs.85%29.aspx">SetUnhandledExceptionFilter</a> didn't get called when the exception code c0000374 raising. But it works fine with the exception code c0000005. Then I tried to use the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679274%28v=vs.85%29.aspx">AddVectoredExceptionHandler</a> instead, and it didn't have the problem, the handler function get called correctly.</p> <p>Is it the API bug? Can I use AddVectoredExceptionHandler instead of SetUnhandledExceptionFilter everywhere?</p> <p>The both functions work correctly with</p> <pre><code>// Exception code c0000005 int* p1 = NULL; *p1 = 99; </code></pre> <p>Only AddVectoredExceptionHandler can capture this exception. (To prove it doesn't depend on the runtime library, I raise the exception manually and it results the same.)</p> <pre><code>// Exception code c0000374 RaiseException(0xc0000374, 0, 0, NULL); </code></pre> <p>Test program.</p> <pre><code>#include &lt;tchar.h&gt; #include &lt;fstream&gt; #include &lt;Windows.h&gt; LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) { std::ofstream f; f.open("VectoredExceptionHandler.txt", std::ios::out | std::ios::trunc); f &lt;&lt; std::hex &lt;&lt; pExceptionInfo-&gt;ExceptionRecord-&gt;ExceptionCode &lt;&lt; std::endl; f.close(); return EXCEPTION_CONTINUE_SEARCH; } LONG WINAPI TopLevelExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) { std::ofstream f; f.open("TopLevelExceptionHandler.txt", std::ios::out | std::ios::trunc); f &lt;&lt; std::hex &lt;&lt; pExceptionInfo-&gt;ExceptionRecord-&gt;ExceptionCode &lt;&lt; std::endl; f.close(); return EXCEPTION_CONTINUE_SEARCH; } int _tmain(int argc, _TCHAR* argv[]) { AddVectoredExceptionHandler(1, VectoredExceptionHandler); SetUnhandledExceptionFilter(TopLevelExceptionHandler); // Exception code c0000374 RaiseException(0xc0000374, 0, 0, NULL); // Exception code c0000005 // int* p1 = NULL; // *p1 = 99; return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload