当“调试断言失败"时自动终止程序过来? [英] Automatically kill a program when "Debug Assertion Failed" comes up?

查看:28
本文介绍了当“调试断言失败"时自动终止程序过来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Visual C++ 程序,我只是将它用于录音,有时它会突然崩溃并出现一个对话框,Visual C++ 调试库"调试断言失败"中止",重试",忽略".

I have a Visual C++ program that I use simply for audio recording and sometimes it totally out of the blue crashes and a dialog box comes up, "Visual C++ Debugging Library" "Debug Assertion Failed" "Abort","Retry","Ignore".

我根本不需要重试或忽略,所以我只想自动运行中止.

I have no need at all to do Retry or Ignore, so I just want Abort to be run automatically.

我有一个批处理/bash 文件,它运行以检测程序是否结束并重新启动它,但是当出现此对话框时,程序仍在运行并且程序一直崩溃直到我注意到它.

I have a batch/bash file that runs to detect that the program ended and to restart it, but when this dialog comes up, the program still runs and the program just remains crashed until I notice it.

推荐答案

运行时函数 _set_error_mode() 可以为您安排.你只需要这样做:

The runtime function _set_error_mode() can arrange this for you. You just need to do this:

_set_error_mode(_OUT_TO_STDERR);

所有错误(包括由断言失败引起的错误)都将其消息打印到 stderr 而不是交互式消息框.这意味着您的应用程序不会阻塞等待输入,而是会立即自行终止.

All errors (including those provoked by assertion failures) will print their messages to stderr rather than an interactive message box. This means that your application won't block waiting for input and will proceed to terminate itself immediately.

这篇关于当“调试断言失败"时自动终止程序过来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆