?? 12_2.cpp
字號(hào):
//12_2.cpp
#include <iostream>
using namespace std;
void MyFunc( void );
class Expt
{
public:
Expt(){};
~Expt(){};
const char *ShowReason() const
{
return "Expt類異常。";
}
};
class Demo
{
public:
Demo();
~Demo();
};
Demo::Demo()
{
cout << "構(gòu)造 Demo." << endl;
}
Demo::~Demo()
{
cout << "析構(gòu) Demo." << endl;
}
void MyFunc()
{
Demo D;
cout<< "在MyFunc()中拋擲Expt類異常。" << endl;
throw Expt();
}
int main()
{
cout << "在main函數(shù)中。" << endl;
try
{
cout << "在try塊中,調(diào)用MyFunc()。" << endl;
MyFunc();
}
catch( Expt E )
{
cout << "在catch異常處理程序中。" << endl;
cout << "捕獲到Expt類型異常:";
cout << E.ShowReason() << endl;
}
catch( char *str )
{
cout << "捕獲到其它的異常:" << str << endl;
}
cout << "回到main函數(shù)。從這里恢復(fù)執(zhí)行。" << endl;
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -