gpt4 book ai didi

linux - 如何获得捕捉 SIGABRT 的信号

转载 作者:可可西里 更新时间:2023-11-01 09:33:17 26 4
gpt4 key购买 nike

我正在 try catch 一个信号,以便让我们的程序正常退出。当我们读取一个我们无法控制的坏文件时,就会发生 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.

关于linux - 如何获得捕捉 SIGABRT 的信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33289260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com