SetUnhandledExceptionFilter 设置未捕获异常处理
通常windows程序长时间运行,会发生各种问题,例如访问异常,内存溢出,堆栈破坏等。
这时候通常希望程序自己能增加处理,而不是依靠系统弹出错误提示框(灰常不友好).
//For proc exception LONG WINAPI ExpFilter(struct _EXCEPTION_POINTERS *pExp) { ACE_DEBUG((LM_ERROR, "Exception code : %X, address: %x Exit! ", pExp->ExceptionRecord->ExceptionCode, pExp->ExceptionRecord->ExceptionAddress)); MessageBox(NULL, "Exception", "提示", MB_OK); //::exit(-1); return EXCEPTION_EXECUTE_HANDLER; } //Test exception // Exception code c0000374
//RaiseException(0xc0000374, 0, 0, NULL); // Exception code c0000005 // int* p1 = NULL; // *p1 = 99;
//For exception in main
::SetUnhandledExceptionFilter(ExpFilter);
PS: The RaiseException function raises an exception in the calling thread.
MSDN中有关SetErrorMode的详细描述,可以这样调用。
//The system does not display a message box when it fails to find a file. Instead, the error is returned to the calling process.
SetErrorMode(SEM_NOOPENFILEERRORBOX)