- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我刚刚注意到了
http://en.cppreference.com/w/cpp/error/uncaught_exception
C++17 将用 std::uncaught_exceptions()
替换返回 bool
的 std::uncaught_exception()
,它返回一个 int
。
对此标准的补充说明如下:
http://isocpp.org/files/papers/n4259.pdf
它没有提供理由,但确实说明了
[Note: When uncaught_exceptions() > 0, throwing an exception can result in a call of std::terminate() (15.5.1). – end note]
这有点奇怪。
这种变化的原因是什么?在 C++17 或该标准的某些 future 版本中是否会出现多个事件异常?
最佳答案
介绍这个的论文是n4152 ,有其基本原理(通常归结为“使 ScopeGuard 工作”)
引用,
as documented at least since 1998 in Guru of the Week #47, it means code that is transitively called from a destructor that could itself be invoked during stack unwinding cannot correctly detect whether it itself is actually being called as part of unwinding. Once you’re in unwinding of any exception, to
uncaught_exception
everything looks like unwinding, even if there is more than one active exception.
和
this uses information already present in major implementations, where current implementations of ScopeGuard resort to nonportable code that relies on undocumented compiler features to make ScopeGuard “portable in practice” today. This option proposes adding a single new function to expose the information that already present in compilers, so that these uses can be truly portable
PS:下面是如何使用编译器特定信息实现此功能的示例:https://github.com/panaseleus/stack_unwinding/blob/master/boost/exception/uncaught_exception_count.hpp
对于一个使用它的简单示例,只需查看 boost.log 的“记录泵”(参见 boost/log/detail/format.hpp 和 boost/log/sources/record_ostream.hpp):它使 BOOST_LOG(lg) << foo();
成为可能如果 foo
则登录它创建的保护对象的析构函数不抛出,也就是说,如果调用析构函数时发生的异常数量不大于调用构造函数时的异常数。
关于c++ - 为什么 std::uncaught_exception 会变成 std::uncaught_exceptions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27741423/
我刚刚注意到了 http://en.cppreference.com/w/cpp/error/uncaught_exception C++17 将用 std::uncaught_exceptions(
什么是 uncaught_exception 的好用例? 最佳答案 Herb Sutter 似乎给出了很好的建议 here .他不知道它有什么好的用途,并说在某些情况下它看起来很有用,但实际上并没有用
我有以下问题。 我有回收的数据库连接(放回池中)。 例如: { session sql(conn_str); // take connection from pool sql.exec("inse
这个问题在这里已经有了答案: How to catch segmentation fault in Linux? (5 个答案) Catching access violation exceptio
介绍 有posts和 articles关于 std::uncaught_exception 的用法和原理。 Functionality这个函数提供的归结为 std::uncaught_exceptio
有些文章的结论是“永远不要从析构函数中抛出异常”,“std::uncaught_exception() 没有用”,例如: http://www.gotw.ca/gotw/047.htm (作者:赫伯·
Herb Sutter 在他的文章中 http://www.gotw.ca/gotw/047.htm指出我们不能在析构函数中使用uncaught_exception, // Why the wron
人们强烈反对从析构函数中抛出异常。取this answer举个例子。我想知道是否std::uncaught_exception()可用于可移植地检测我们是否由于某些其他异常而处于展开堆栈的过程中。 我
我在 DLL 中有一个类,它有一个析构函数来检查 std::uncaught_exception()。如果在可执行文件的 try/catch block 中使用,如果抛出异常,它不会说 true。 下
C++ 标准库似乎有 std::uncaught_exception , 微软有这个 exact function . 但微软也有__uncaught_exception .我在文档中看不到任何显着差
我正在测试最近在 C++17 下测试期间出现的问题。这是源文件: $ cat test.cxx #if __EXCEPTIONS && __has_feature(cxx_exceptions) #
我注意到我的 Mac 上的 stock libc++ 中缺少 std::uncaught_exceptions 符号: $ clang++ -v; otool -L /usr/lib/libc++.d
LuaJIT 手册 states : Lua errors can be caught on the C++ side with catch(...). The corresponding Lua e
这个问题在这里已经有了答案: Scope(failure) in C++11? (2 个回答) 关闭9年前。 毫无疑问,很多人都熟悉 Alexandrescus 先生的 ScopeGuard 模板(现
我是一名优秀的程序员,十分优秀!