当我在 Windows 10 上的 Visual Studio 2015 中运行此代码时,看不到输出
That was unexpected
它可以在 Linux 上的 gcc 5.3 中运行。
class X {};
class Y {};
class Z : public X {};
class W {};
void f() throw(X, Y) // list what exceptions can be thrown
{
int n = 0;
if (n) throw X(); // OK
if (n) throw Z(); // also OK
throw W(); // will call std::unexpected()
}
int main() {
std::set_unexpected([] {
std::cout << "That was unexpected" << std::endl;
std::abort();
});
f();
}
最佳答案
尽管语法已被接受,但 Visual C++ 从未实现异常规范。
无论如何,它们在 C++11 及更高版本中已被弃用。
可能是由于主 Windows C++ 编译器不符合要求的结果。
同样,我记得 Visual C++ 从未实现过 std::uncaught_exception
,但对此我不太确定。在使用和依赖之前值得检查。 …文档检查:the documentation Visual C++ 2015 指出
” On devices,
uncaught_exception
is only supported on Windows CE 5.00 and higher versions, including Windows Mobile 2005 platforms
所以在桌面平台上它显然是受支持的。
关于c++ - 当我调用 std::abort() 时,未显示 cout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36290605/