12_11.cpp
来自「10个比较经典的C++程序。初学者就先多学习学习别人吧。」· C++ 代码 · 共 28 行
CPP
28 行
#include <iostream>
using namespace std;
void MyFunc( void );
class Expt
{ public:
Expt(){};
~Expt(){};
const char *ShowReason() const { return "Expt Class exception"; }
};
class Demo
{ public:
Demo(){ cout << "Constructing Demo." << endl;}
~Demo(){ cout << "Destructing Demo." << endl;}
};
void MyFunc()
{ Demo D; cout<< "In MyFunc(), throw Expt class exception" << endl; throw Expt();}
int main()
{ cout << "In main function" << endl;
try { cout << "In try, using MyFunc()" << endl; MyFunc(); }
catch( Expt E )
{ cout << "In catch, catch Expt type exception:";
cout << E.ShowReason() << endl;
}
catch( char *str ) { cout << "Catch other exception" << str << endl; }
cout << "return main" << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?