Alo*_*ave 1 c++ exception-handling
我只是在视觉工作室中使用异常,并且使用上面的代码我期待,因为我的异常规范没有提到任何应该抛出bad_exception的内容.但实际发生的是异常被适当的处理程序捕获.为什么这样?我错过了IDE中的某些设置或其他内容吗?
虽然我被困在上面提到的,实际上我试图找到问题的答案,如果我有一个例外空白规范然后被称为什么?在意外()方法或*bad_exception*将如果双方以什么顺序来抛出?这是代码.
#include "stdafx.h"
#include <stdio.h>
#include <exception>
#include <iostream>
using namespace std;
class A
{
public:
int i;
};
void myunexpected ()
{
cerr << "unexpected called\n";
}
void doSomething(void) throw();
void doSomething(void) throw()
{
A obj;
obj.i= 100;
throw obj;
}
int _tmain(int argc, _TCHAR* argv[])
{
set_unexpected (myunexpected);
try
{
doSomething();
}
catch (bad_exception be)
{
puts("Caught something");
}
catch (A &obj)
{
puts("Caught Integer");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)