Wil*_*mKF 4 c++ exception try-catch ellipsis throw
当没有待处理的异常在堆栈中处理更高时,C++标准对于以下代码应该说什么呢?
try {
throw;
} catch (...) {
cerr << "Caught exception." << endl;
}
Run Code Online (Sandbox Code Playgroud)
没有任何对象的投掷会被抓住吗?
Jam*_*lis 13
从2003 C++标准§15.1[except.throw]/8:
如果当前没有处理异常,则执行 不带操作数调用的 throw-expression
terminate().
因此,在您的示例中,由于当前没有处理任何异常,因此不会抛出任何异常,而是terminate()调用异常.由于terminate()不返回,您的catch区块将永远不会被输入.
| 归档时间: |
|
| 查看次数: |
472 次 |
| 最近记录: |