我正在尝试处理意外的异常,但无法使其工作.这是来自C++ Reference的示例
// set_unexpected example
#include <iostream>
#include <exception>
using namespace std;
void myunexpected () {
cerr << "unexpected called\n";
throw 0; // throws int (in exception-specification)
}
void myfunction () throw (int) {
throw 'x'; // throws char (not in exception-specification)
}
int main (void) {
set_unexpected (myunexpected);
try {
myfunction();
}
catch (int) { cerr << "caught int\n"; }
catch (...) { cerr << "caught other exception (non-compliant compiler?)\n"; }
return 0;
}
Run Code Online (Sandbox Code Playgroud)
他们说输出应该是:输出:
出乎意料的叫
抓住了
当我尝试时不会发生这种情况.我的输出是:
捕获其他异常(不兼容的编译器?)
我正在使用VS2010 sp1