In C ++, dereferencing a null pointer causes undefined behavior, which does not necessarily mean that an exception is thrown. On Unix systems, for example, a SIGSEGV signal occurs instead.
On Windows, access violations raise the SEH exception . SEH exceptions do not match C ++ exceptions; they are processed using __try/__except(unlike operators try/catch). An unhandled SEH exception throws an unhandled exception filter, which you can set with SetUnhandledExceptionFilter.
#include <Windows.h>
#include <iostream>
LONG WINAPI MyFilter(EXCEPTION_POINTERS * )
{
std::cout << "An uncaught exception was detected!\n";
return EXCEPTION_CONTINUE_SEARCH;
}
int main()
{
SetUnhandledExceptionFilter(MyFilter);
*(char volatile *)0 = 0;
}
source
share