?? 21-7.txt
字號:
/* 范例:21-7 嵌套例外處理(Nested Try) */
#include <iostream.h>
int f()
{
throw runtime_error("RunTime_Error");
}
void main()
{
try
{
try
{
try
{
throw("測試嵌套例外處理!\n");
cout << "這個語句將不被輸出!\n";
}
catch(const char *str1){throw str1;}
}
catch(const char *str2)
{
cerr << "Failure, Not The Proper Way!!\n" << str2;
}
f();
}
catch(const exception& e)
{
cerr << "執(zhí)行不當(dāng)!請勿再做任何動作!\n"<< e.what() << endl;
}
cout << "危險!";
getchar();
}
程序執(zhí)行結(jié)果﹕
Failure, Not The Proper Way!!
測試嵌套例外處理!
執(zhí)行不當(dāng)!請勿再做任何動作!
RunTime_Error
危險!
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -