- #pragma once
- #include
- class Up{};
- class Fit{};
- void g();
- void f(int i)throw(Up,Fit){
- switch(i){
- case 1:
- throw Up();
- case 2:
- throw Fit();
- }
- g();
- }
- void g(){
- int i=1;
- i/0;
- throw bad_exception();
- }
- void my_unexpected(){
- cout<<"unexpected exception thrown"<<endl;
- exit(0);
- }
- #ifndef DEBUG
- #define DEBUG 1
- void excute(){
- set_unexpected(my_unexpected);
- for(int i=1;i<=3;i++){
- try{
- f(i);
- }
- catch(Up){
- cout<<"Up caught"<<endl; }
- catch(Fit){
- cout<<"Fit caught"<<endl; }
- }
- }
- #endif
C++ unexpected throw exception
最新推荐文章于 2023-05-26 08:39:14 发布