小编npl*_*tis的帖子

奇怪的C++异常"定义"

我的一个学生提交了一些类似于下面的C++代码.代码编译并运行,但该throw语句产生以下消息:

抛出'int'实例后调用terminate

如果我创建函数void编译器抱怨

无效使用'void'

在包含该throw声明的行上(预期).

class TestClass
{
public:
    int MyException()
    {
        return 0;
    }

    void testFunc()
    {
        throw MyException();
    }
};


int main(int argc, char** argv)
{
    TestClass tc;
    tc.testFunc();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

那么,MyException由于代码是"正确的" ,C++如何解释?

c++ exception

0
推荐指数
1
解决办法
219
查看次数

标签 统计

c++ ×1

exception ×1