Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当堆栈更高层没有处理未决异常时,C++ 标准应该对以下代码发生什么?
try { throw; } catch (...) { cerr << "Caught exception." << endl; }
没有物体的投掷会被接住吗?
从 2003 C++ 标准 §15.1[except.throw]/8 开始:
如果当前没有处理异常,则执行 不带操作数调用的throw 表达式terminate()。
terminate()
因此,在您的示例中,由于当前未处理任何异常,因此不会抛出任何异常,而是terminate()调用它。由于terminate()不返回,您的catch块将永远不会被输入。
catch