相关疑难解决方法(0)

从信号处理程序中抛出异常

我们有一个库,可以处理错误报告的许多方面.我的任务是将此库移植到Linux.当我的小测试套件运行时,其中一个测试失败了.测试的简化版本如下所示.

// Compiler: 4.1.1 20070105 RedHat 4.1.1-52
// Output: Terminate called after throwing an instance of 'int' abort

#include <iostream>
#include <csignal>
using namespace std;

void catch_signal(int signalNumber)
{
    signal(SIGINT, SIG_DFL);
    throw(signalNumber);
}

int test_signal()
{
    signal(SIGINT, catch_signal);

    try
    {
        raise(SIGINT);
    }
    catch (int &z)
    {
        cerr << "Caught exception: " << z << endl;
    }
    return 0;
}

int main()
{
    try
    {
        test_signal();
    }
    catch (int &z)
    {
        cerr << "Caught unexpected exception: " << z << endl; …
Run Code Online (Sandbox Code Playgroud)

c++ signals exception

22
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

exception ×1

signals ×1