小明思考

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

When program crashed (windows)

Posted on 2008-11-17 13:54 小明 阅读(3249) 评论(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

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理