c++ - 当我调用 std::abort() 时,未显示 cout

标签 c++ exception visual-studio-2015 iostream abort

当我在 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/

相关文章:

c++ - 对于类中动态大小的数组,std::vector 是否优于堆数组?

c - 整个缓冲区初始化导致异常

c# - 无法加载或创建VS 2015.1。项目。无法创建Visual C#2015编译器

c++ - 无法在 VS2015 的 ARM 模式下构建 C++ 静态库(Windows Phone 8.1)

visual-studio - TypeScript - Visual Studio 2015 Intellisense 找不到模块

c++ - 基类指针可以指向派生类对象。为什么反之不成立?

c++ - 如何为类定义 'final' 成员函数

c++ - 纯虚函数调用

java - 我的 try catch 没有显示警告消息

C 访问冲突写入位置