【发布时间】:2015-10-04 00:26:07
【问题描述】:
我正在通过C++ FAQ 2nd Edition, FAQ 9.04- What is an exception specification?。
这里提到如果我们从一个函数中抛出一个意外的异常,该函数的签名指定了一组预定义的异常类型,它应该调用unexpected()->terminate()->abort()。
但是我的程序捕捉到了意外的异常并且没有abort()ing 它,为什么?
#include<iostream>
using namespace std;
class Type1{};
class Type2{};
class Type3{};
void func() throw(Type1, Type2)
{
throw Type3();
}
int main()
{
try{
func();
}
catch (Type1 &obj1)
{
cout << "Type1 is caught" << endl;
}
catch (Type2 &obj2)
{
cout << "Type2 is caught" << endl;
}
catch (Type3 &obj3)
{
cout << "Type3 is caught" << endl;
}
}
在这里我得到了不应该发生的输出Type3 is caught。
IDE:VS2013
【问题讨论】: