本文介绍了catch(...)在throw上工作;没有对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当没有待处理的异常处理在堆栈中更高的时候,C ++标准会对下面的代码发生什么?

What does C++ standard say should happen for the following code when there is no pending exception being processed higher up the stack?

try {
  throw;
} catch (...) {
  cerr << "Caught exception." << endl;
}

没有对象的throw会被捕获吗?

Will the throw with no object be caught or not?

推荐答案

从2003 C ++标准§15.1[except.throw] / 8:

From the 2003 C++ Standard §15.1[except.throw]/8:

所以,在你的例子中,因为当前没有异常处理,所以不会抛出任何异常, terminate / code>。由于 terminate()不返回,您的 catch 块将永远不会输入。

So, in your example, since no exception is currently being handled, nothing is thrown and instead terminate() is called. Since terminate() does not return, your catch block will never be entered.

这篇关于catch(...)在throw上工作;没有对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 03:08