捕捉程序崩溃事件的方法

 
 

#include <Windows.h>
#include <tchar.h>

// 处理Unhandled Exception的回调函数  
//  
LONG ApplicationCrashHandler(EXCEPTION_POINTERS *pException)  
{     
	// 在这里添加处理程序崩溃情况的代码  
	// 现在很多软件都是弹出一个发送错误报告的对话框  

	// 这里以弹出一个错误对话框并退出程序为例子  
	//  
	FatalAppExit(-1,  _T("*** Unhandled Exception! ***"));  

	return EXCEPTION_EXECUTE_HANDLER;  
} 

int main(int argc, char* argv[])  
{ 
	// 设置处理Unhandled Exception的回调函数  
	//   
	SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler); 
	// 除零,人为的使程序崩溃  
	//  
	int i = 13;  
	int j = 0;  
	int k = i / j;  

	return 0;  
}  

猜你喜欢

转载自blog.csdn.net/q277055799/article/details/53088675
今日推荐