code:
#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;
}
本文演示了如何在C++中使用自定义的全局终止处理函数来接管默认的终止行为,并展示了通过抛出和捕获不同类型的异常来实现特定功能的例子。
8万+

被折叠的 条评论
为什么被折叠?



