windows 可以禁用“应用程序错误”对话框吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/735170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:17:08  来源:igfitidea点击:

Can the "Application Error" dialog box be disabled?

c++windowsdebuggingmemorybuild-automation

提问by mch

I am using Hudson as a continuous integration server to test C/C++ code. Unfortunatly, I have a bug somewhere that causes memory corruption, so on some Windows machines I will sometimes get a "Application Error" dialog box explaining that an instruction referenced memory that could not be read. This dialog box pops up and basically hangs the test run, as it requires manual intervention.

我使用 Hudson 作为持续集成服务器来测试 C/C++ 代码。不幸的是,我在某处有一个导致内存损坏的错误,因此在某些 Windows 机器上,我有时会收到一个“应用程序错误”对话框,说明一条指令引用了无法读取的内存。弹出这个对话框,基本挂了试运行,因为需要人工干预。

Is there a way to prevent this dialog box from appearing, so that the test run simply fails and is reported as such in Hudson?

有没有办法防止这个对话框出现,这样测试运行就会失败并在 Hudson 中报告这样的结果?

Is it possible to automatically generate a minidump instead of showing the dialog?

是否可以自动生成小型转储而不是显示对话框?

采纳答案by rkb

  1. Use "Disable error reporting", as Mr. Gently suggests. See also this PC World article.
  2. If you happen to have MS Visual Studio on your build machine, it will catch Application Errors and pop up a dialog box. To disable these dialogs (and also the Just-In-Time Debugging feature of Visual Studio), run the command drwtsn32.exe -ito set Dr. Watson as the default system debugger. Dr. Watson will generate a core dump and silently exit. (See this Microsoft Knowledge Base article: http://support.microsoft.com/kb/q121434/.)
  1. 正如 Gently 先生建议的那样,使用“禁用错误报告”。另请参阅这篇 PC World 文章
  2. 如果您的构建机器上碰巧有 MS Visual Studio,它会捕获应用程序错误并弹出一个对话框。要禁用这些对话框(以及 Visual Studio 的即时调试功能),请运行命令drwtsn32.exe -i将 Dr. Watson 设置为默认系统调试器。Watson 博士将生成核心转储并静默退出。(请参阅此 Microsoft 知识库文章:http: //support.microsoft.com/kb/q121434/。)

回答by Richard Corden

You can also do something like this programaticaly using SetErrorMode. See thisarticle for more details.

您还可以使用SetErrorMode 以编程方式执行此类操作。有关更多详细信息,请参阅文章。

A simple example of how to use it is to do the following:

如何使用它的一个简单示例是执行以下操作:

SetErrorMode(GetErrorMode () | SEM_NOGPFAULTERRORBOX);

The above 'ORs' the current mode with our desired addition.

上面的“或”将当前模式与我们想要的相加。

回答by johnny

In addition to what rkb said, if you are running Windows XP 64bit, there are two sets of values. The ones in the usual registry location and the ones under the Wow6432Nodekey in HKLM. In order to update both, run drwtsn32.exe -ifrom both %SYSTEMROOT%\system32and %SYSTEMROOT%\SysWOW64.

除了rkb所说的,如果你运行的是Windows XP 64bit,还有两组值。在平时的注册表位置和那些下的那些Wow6432Node重点HKLM。为了更新两者,drwtsn32.exe -i从两者%SYSTEMROOT%\system32和运行%SYSTEMROOT%\SysWOW64

回答by dirkgently

Disable error reporting via:

通过以下方式禁用错误报告:

  • Registry editing -- add your application to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealth\ErrorReporting\ExclusionList, OR
  • Right-Click on My Computer, go to the Advanced Tab, and choose the "Disable error reporting" option, OR
  • You can navigate to the services console in Administrative tools, find the Error Reporting Service, go into properties and disable it
  • 注册表编辑 -- 将您的应用程序添加到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealth\ErrorReporting\ExclusionList,或
  • 右键单击“我的电脑”,转到“高级”选项卡,然后选择“禁用错误报告”选项,或
  • 您可以导航到管理工具中的服务控制台,找到错误报告服务,进入属性并禁用它

回答by Chris Dodd

You can use the various _CrtSetReport functions to control the way the C/C++ runtime responds to various errors (_CrtSetReportHook, _CrtSetReportMode, _CrtSetReportFile, _CrtSetReportHook2)

您可以使用各种 _CrtSetReport 函数来控制 C/C++ 运行时响应各种错误的方式(_CrtSetReportHook、_CrtSetReportMode、_CrtSetReportFile、_CrtSetReportHook2)

回答by CLaRGe

Use a try/catch statement to catch the exception and handle it the way you want.

使用 try/catch 语句捕获异常并按照您想要的方式处理它。