utn*_*tim 1 c++ exception-handling stack-unwinding
问:在堆栈展开时引发并捕获异常是安全的,还是应用程序terminate在第二次引发时调用?
最小的例子:
void some_function()
{
try
{
// do stuff here that can throw
throw std::runtime_error("blah");
} catch(const std::exception& re)
{
try // this code could be in some function called from here
{
// do something with re here that throws a logical_error
throw std::logical_error("blah blah"); // does this call terminate?
} catch(const std::logical_error& le)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
看完这个问题我很好奇。
注意:我知道您可以/应该catch(...)在析构函数中使用,但是通常try/catch在一个catch块中包含有意义-也许在调用异常的某些函数中(re在我的示例中)?
| 归档时间: |
|
| 查看次数: |
196 次 |
| 最近记录: |