InQ*_*ive 7 c++ exception abort
我正在经历C++ FAQ 2nd Edition, FAQ 9.04- What is an exception specification?
.
在那里,提到如果我们从其签名指定一组预定义异常类型的函数抛出一个意外异常,它应该调用unexpected()->terminate()->abort()
.但是我的程序捕获了意外的异常而不是abort()
它,为什么?
#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;
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我得到的输出Type3 is caught
不应该发生.
IDE:VS2013
来自 MSDN:
除 throw() 之外的函数异常说明符会被解析但不会被使用。这不符合 ISO C++ 规范第 15.4 节
Visual C++ 根本不遵循标准(引用Mohit 答案中的标准)。
编辑:关于子问题“为什么不?” 我尝试从评论中总结已经说过的话。
归档时间: |
|
查看次数: |
277 次 |
最近记录: |