【发布时间】:2014-08-19 19:33:39
【问题描述】:
我有以下例子:
void Unhandled() {
cout << "Unhandled exception!" << endl;
// exit(-1);
}
int main(){
float a, b;
set_terminate(Unhandled);
try{
cout << "Input two numbers: ";
cin >> a >> b;
if (b == 0)
throw "Division by zero!";
cout << a / b;
}
catch (int n){
cout << "Error ID: " << n << endl;
}
return 0;
}
我编写了这段代码来处理“未处理”异常,但它仍然强制我使用“退出”函数退出程序,或者默认情况下调用“中止”。是否可以避免这种情况,以便在调用“未处理”后继续正常执行应用程序?
【问题讨论】:
标签: c++ exception-handling unhandled-exception