当我调用 std::abort() 时未显示 cout
Posted
技术标签:
【中文标题】当我调用 std::abort() 时未显示 cout【英文标题】:cout not shown when I call std::abort() 【发布时间】:2016-03-29 17:02:51 【问题描述】:当我在 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();
【问题讨论】:
您可以尝试写信给std::cerr
。
我刚才试了std::cerr还是不行。
【参考方案1】:
Visual C++ 从未实现异常规范,尽管 语法 被接受。
无论如何,它们在 C++11 及更高版本中已被弃用。
可能是由于主 Windows C++ 编译器不符合要求。
同样,我记得 Visual C++ 从未实现过std::uncaught_exception
,但对此我不太确定。值得在使用和依赖之前检查。 … 文档检查:the documentation for Visual C++ 2015 声明
” 在设备上,
uncaught_exception
仅在 Windows CE 5.00 及更高版本(包括 Windows Mobile 2005 平台)上受支持
所以在桌面平台上它显然是受支持的。
【讨论】:
另请注意,在 Windows Clang 上也是如此 好的,也许 MS 文档是错误的,因为它似乎不适用于 Windows 10 桌面平台。感谢您找到这个! @Damian:你的意思是std::uncaught_exception
?
是的,std::uncaught_exception 似乎没有被调用。以上是关于当我调用 std::abort() 时未显示 cout的主要内容,如果未能解决你的问题,请参考以下文章
Cordova / Ionic:在设备上模拟或运行时未处理 $http 请求
在 viewDidLoad 外部调用方法时未显示相机胶卷中的最后一张图像
为啥当我使用 presentModelViewController 时未在我的 UITabBArController 中调用 viewWillAppear?