2
#include "iostream"
#include "conio.h"
#include "exception"
#include "cstdlib"
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"; }
getch();
return 0;
}
輸出(當在Visual Studio 2008中執行): 捕獲其他異常異常處理 - set_unexpected()不能調用
但是,我期待(不符合標準的編譯器?)輸出是:
意外稱爲
抓INT
注:我在Visual Studio中執行該計劃2008年
Thanks Man: - ):D ;-) – Jatin 2012-04-07 18:12:45