小明思考

高性能服务器端计算
posts - 65, comments - 333, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

When program crashed (windows)

Posted on 2008-11-17 13:54 小明 阅读(1361) 评论(0)  编辑 收藏 引用 所属分类: Win32Debug
天下没有不crash的程序。

Crash作为一个客观存在的现实,每个程序员都应该意识到这个问题,才能最大限度的降低crash所带来的危害。

让我们先来看看几种死亡对话框


Figure-1 Crash MessageBox in Windows 2000


Figure-2 Crash MessageBox in Windows XP

让我们看看哪些因素影响程序Crash的时候的行为

1 . Error Mode

--cut from microsoft--
Each process has an associated error mode that indicates to the system how the application is going to respond to serious errors. Serious errors include disk failure, drive-not-ready errors, data misalignment, and unhandled exceptions. An application can let the system display a message box informing the user that an error has occurred, or it can handle the errors. To handle these errors without user intervention, use the SetErrorMode function. After calling SetErrorMode and specifying appropriate flags, the system will not display the corresponding error message boxes.
--cut from microsoft--

也就是说我们可以调用来SetErrorMode(SEM_NOGPFAULTERRORBOX)来屏蔽掉"Death MessageBox"的出现。

具体的API使用参考http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx

另外值得一提的一点是,父子进程默认使用相同的ErrorMode,但是你可以在CreateProcess通过指定CREATE_DEFAULT_ERROR_MODE来disable.

2.注册表中的HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug

有两个key,第一个是auto,指定程序crash的时候要不要自动的load debugger
如果为1,就不会显示"Death MessageBox"而直接调用debugger了

另外一个是debugger,指定默认的debugger.


最后上传一个测试程序来体会一下

Click here to download TestCrash

标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]

相关链接:
网站导航: