ExampleTwo.cpp
上传用户:skywee
上传日期:2021-12-09
资源大小:141k
文件大小:1k
- #include <iostream>
- #include <string>
- using namespace std;
- class MyException
- {
- int a;
- string s;
- public:
- MyException()
- {
- a=0;
- s = "Error";
- }
- MyException(int id, string msg)
- {
- a=id;
- s = msg;
- }
- void display()
- {
- cout<<s<<" and ErrorID = "<< a;
- }
- };
- int main()
- {
- void f1();
- //f1();
- try
- {
- f1();
- }
- catch(double)
- {
- cout<<"OK0!"<<endl;
- }
- cout<<"end0"<<endl;
- return 0;
- }
- void f1()
- {
- void f2();
- try
- {
- f2();
- }
- catch(char)
- {
- cout<<"OK1!";
- }
- cout<<"end1"<<endl;
- }
- void f2()
- {
- void f3();
- try
- {
- f3();
- }
- catch(int)
- {
- cout<<"Ok2!"<<endl;
- }
- cout<<"end2"<<endl;
- }
- void f3()
- {
- double a=0;
- try
- {
- throw a;
- }
- catch(float)
- {
- cout<<"OK3!"<<endl;
- }
- try
- {
- MyException e(105,"Data Error!!!");
- throw e;
- }
- catch (MyException e)
- {
- e.display();
- }
- cout<<"end3"<<endl;
- }