C++ 异常处理 terminate函数使用


C++ 异常处理 terminate函数使用代码:

#include <iostream>
using namespace std;

void terminator(){
 cout << "I 'll be back!" <<endl;
 exit(0);
}

void (*old_terminate)() = set_terminate(terminator);


class B{
public :
 class A{};
 void f(){
  cout<<"B::f()"<<endl;
  throw A();
 }
 ~B(){
  throw 'c';
 }
};

int main(){
 try{
  B b;
  b.f();
 }catch(...){
  cout<<"inside catch(...)"<<endl;
 }
 return 0;
}

相关内容