?? 21-2.txt
字號:
/* 范例:21-2 try...throw...catch */
#include <iostream.h>
using namespace std;
static void f()
{
throw runtime_error("a runtime error");
}
int main()
{
try
{
f();
}
catch(const exception& e)
{
cerr<< "這是一個默認的錯誤信息:" << e.what() << endl;
} // 使用what成員函數輸出錯誤信息
getchar();
}
程序執行結果﹕
(先迸出這個警告,若未選Stop on C++ Exceptions則無此警告信息)
Project p21-2.exe raised exception blass runtime_error with message 'Exception
Address:0x682FA6'. Process stopped. Use Step or Run to continu
(當出現這個信息后,請再編譯這程序一次,就會看到以下錯誤信息)
這是一個內定的錯誤信息: a runtime error
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -