ExampleFour.cpp
上传用户:skywee
上传日期:2021-12-09
资源大小:141k
文件大小:1k
- #include <iostream>
- using namespace std;
- class CErrorBase
- {
- public:
- virtual void PrintError()
- {
- cout<<"CErrorBase"<<endl;
- }
- };
- class CErrorOverflow:public CErrorBase
- {
- public:
- virtual void PrintError()
- {
- cout<<"CErrorOverflow"<<endl;
- }
- };
- class CErrorNullPointer:public CErrorBase
- {
- public:
- virtual void PrintError()
- {
- cout<<"CErrorNullPointer"<<endl;
- }
- };
- class CErrorZeroDevide:public CErrorBase
- {
- public:
- virtual void PrintError()
- {
- cout<<"CErrorZeroDevide"<<endl;
- }
- };
- void Func(int i)
- {
- if(i%3==0)
- throw CErrorOverflow();
- if(i%4==0)
- throw CErrorNullPointer();
- if(i%5==0)
- throw CErrorZeroDevide();
- }
- int main(int argc, char* argv[])
- {
- int i;
- cin>>i;
- try
- {
- Func(i);
- }
- catch(CErrorBase &e)
- {
- e.PrintError();
- }
- return 0;
- }