停止 MSVC++ 调试阻塞当前进程的错误?
Windows 上任何失败的 ASSERT 语句都会导致出现以下调试消息并冻结应用程序执行。 我意识到这是预期的行为,但它定期在无头机器上运行,因此可以防止单元测试失败,而不是无限期地等待用户输入。
是否有注册表项或编译器标志可以用来防止此消息框请求用户输入,同时仍然允许测试在 ASSERT 下失败?
基本上,我想在不修改任何代码的情况下执行此操作,只需更改编译器或 Windows 选项。
谢谢!
Microsoft Visual C++ 调试库 ASSERT http:// img519.imageshack.us/img519/853/snapshotbu1.png
Any failed ASSERT statements on Windows cause the below debug message to appear and freeze the applications execution. I realise this is expected behaviour but it is running periodically on a headless machine so prevent the unit tests from failing, instead waiting on user input indefinitely.
Is there s a registry key or compiler flag I can use to prevent this message box from requesting user input whilst still allowing the test to fail under ASSERT?
Basically, I want to do this without modifying any code, just changing compiler or Windows options.
Thanks!
Microsoft Visual C++ Debug Library ASSERT http://img519.imageshack.us/img519/853/snapshotbu1.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这是 _CrtDbgReport 显示的对话框,用于 _CRT_ASSERT 类型的报告。 使用 _CrtSetReportHook,您可以为整个应用程序定制该行为。 (即需要一个本地更改)特别是,您可以在断言失败后继续执行,从而忽略它。
I think this is a dialog shown by _CrtDbgReport for reports of type _CRT_ASSERT. With _CrtSetReportHook, you can tailor that behavior for your entire application. (i.e. requires one local change) In particular, you can continue execution after a failed assertion, thus ignoring it.
来自 MSDN 关于 ASSERT 宏的信息:
在 MFC ISAPI 应用程序中,调试模式下的断言将弹出一个模式对话框(ASSERT 对话框现在默认为模式对话框); 这将中断或挂起执行。 要抑制模式断言对话框,请将以下行添加到项目源文件 (projectname.cpp) 中:
完成此操作后,您可以使用 WebDbg 工具 (WebDbg.exe) 查看断言。
From MSDN about the ASSERT macro:
In an MFC ISAPI application, an assertion in debug mode will bring up a modal dialog box (ASSERT dialog boxes are now modal by default); this will interrupt or hang the execution. To suppress modal assertion dialogs, add the following lines to your project source file (projectname.cpp):
Once you have done this, you can use the WebDbg tool (WebDbg.exe) to see the assertions.
在单元测试上下文中,通常最好将 ASSERT(实际上是
_CrtDbgReport
调用)转换为某些异常,通常是 std::exception,其中包含一些信息性文本。这往往会以失败的形式出现在单元测试的输出日志中。
这正是您想要的:失败的 ASSERT 应该是失败的单元测试。
通过放入您的报告挂钩函数来完成此操作,具体使用:
_CrtSetReportHook()
In a unit-test context, it is often good to convert ASSERTs (actually
_CrtDbgReport
calls) into some exception, typically a std::exception, that contains some informative text.This tends to wend its way out to the unit test's output log as a fail.
That's just what you want: A failed ASSERT should be a failed unit test.
Do that by throwing in your report-hook function, as specified using:
_CrtSetReportHook()