如何获得捕捉 SIGABRT 的信号

How to get signal to catch SIGABRT

我正在尝试捕捉一个信号,以便让我们的程序正常退出。当我们读取一个我们无法控制的坏文件时,就会发生 SIGABRT。这是一个多平台程序,因此我们需要在 windows、linux 和 mac.

中运行的程序

出于某种原因,当我在 signal handling example 中添加 signal_callback_handler 和 运行 Windows 中的问题测试时,它仍然会出现中止弹出窗口像我们以前一样的盒子。如何在中止弹出窗口发生之前重定向?我希望我们的程序能够正常退出。

//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 documentation for abort(强调我的):

By default, when an app is built with the debug runtime library, the abort routine displays an error message before SIGABRT is raised. [...] To suppress the message, use _set_abort_behavior to clear the _WRITE_ABORT_MSG flag.