如何获得信号来捕捉SIGABRT

我试图捕捉一个信号,所以我可以让我们的程序正常退出。 当我们读取一个我们无法控制的坏文件时,会发生SIGABRT。 这是一个多平台的程序,所以我们需要在windows,linux和mac中有效的东西。

出于某种原因,当我像信号处理例子那样添加signal_callback_handler,然后在Windows中运行问题testing时,它仍然会出现像我们以前那样的中止popup框。 如何在中止popup之前redirect? 我想我们的程序正常退出。

//constructor example::example(const string theString) { signal(SIGABRT, signal_callback_handler); } void example::signal_callback_handler(int sigNum) { //want to handle gracefully here, but it's not getting caught } bool example::someMethod() { FileHandle.openFile(problemDocument); //this openFile is where the SIGABRT happens } 

谢谢!

你描述的行为是记录的。

从Visual Studio文档中取消 (重点是我的):

默认情况下,使用调试运行时库构建应用程序时,中止例程引发SIGABRT 之前显示错误消息。 […]要禁止该消息,请使用_set_abort_behavior清除_WRITE_ABORT_MSG标志。