ExampleThree.cpp
上传用户:skywee
上传日期:2021-12-09
资源大小:141k
文件大小:1k
- #include <iostream>
- using namespace std;
- enum ENUM_ERROR{StackOverflow,NullPointer,ZeroDevide,OtherError};
- void Func(int i)
- {
- try{
- if(i%3==0)
- throw StackOverflow;
- if(i%4==0)
- throw NullPointer;
- if(i%5==0)
- throw ZeroDevide;
-
- }
- catch (int OtherError)
- {
- throw OtherError;
- }
- }
- int main(int argc, char* argv[])
- {
- int i;
- cin>>i;
- try
- {
- Func(i);
- }
- catch(ENUM_ERROR e)
- {
- switch(e)
- {
- case StackOverflow:
- cout<<"StackOverflow"<<endl;
- break;
- case NullPointer:
- cout<<"NullPointer"<<endl;
- break;
- case ZeroDevide:
- cout<<"ZeroDevide"<<endl;
- break;
- case OtherError:
- cout<<"ZeroDevide"<<endl;
- break;
- }
- }
- catch(...)
- {
- cout<<"Unknown exception!"<<endl;
- }
- return 0;
- }