下面的简单代码

// g++ centro.cc -o centro

#include <iostream>
using namespace std;

int  main(int argc, char *argv[])
{
    try
    {
        cout << "Going to throw" << endl;
        throw;
    }
    catch(...)
    {
        cout << "An exception occurred" << endl;
    }
    return 0;
}

产生中止:
Going to throw
terminate called without an active exception
Aborted (core dumped)

我不明白出了什么问题,有人能指出我正确的方向吗?

最佳答案

你的线

throw;

是在catch块中重新引发异常的语法。

您应该写:
throw std::exception();

关于时间:2019-05-02 标签:c++trivialtry-catch 导致中止,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11308864/

10-13 07:04