11_100.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- #include<iostream.h>
- void fun(void);
- class evil
- {
- public:
- evil(){}
- ~evil(){}
- const char* ShowReason() const
- {
- return "evil类异常。";
- }
- };
- class A
- {
- public:
- A();
- ~A();
- };
- A::A()
- {
- cout<<"构造A。"<<endl;
- }
- A::~A()
- {
- cout<<"析构A。"<<endl;
- }
- void fun()
- {
- A D;
- cout<<"在fun()中抛掷evil类异常,注意自动调用局部对象的析构函数。"<<endl;
- throw evil();
- }
- void main()
- {
- cout<<"在main函数中"<<endl;
- try
- {
- cout<<"在try块中调用fun()。"<<endl;
- fun();
- }
- catch(evil E)
- {
- cout<<"在catch异常处理程序中。"<<endl;
- cout<<"捕获到evil类型异常:";
- cout<<E.ShowReason()<<endl;
- }
- catch(char *str)
- {
- cout<<"捕获到其它异常:"<<str<<endl;
- }
- cout<<"回到main函数。从这里恢复执行。"<<endl;
- }