c++ - 嵌套异常和原始类型

标签 c++ c++11

当我捕获的异常是原始类型时,我可以使用 std::throw_with_nested 吗?

据说,新类型是从捕获的异常和新的异常中派生出来的。但我无法从 int 等原始类型派生。因此我不能对原始类型使用嵌套异常。是真的吗?

最佳答案

我的标准拷贝是这样说的:

18.8.6/7 Throws: if U is a non-union class type not derived from nested_exception, an exception of unspecified type that is publicly derived from both U and nested_exception and constructed from std::forward<T>(t), otherwise std::forward<T>(t).

所以 throw_with_nested(42)应该throw 42;

关于c++ - 嵌套异常和原始类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22002331/

相关文章:

c++ - 类型转换 boost::units::quantity 加倍

c++ - 引用枚举时 C++ 2003 和 C++ 2011 之间代码不兼容的原因

c++ - 检查嵌套的模板类

c++ - 如何在回溯中显示 lambda 函数?

c++ - Delphi/C++ Builder - 在 TDBGrid 中设置事件/选定行颜色

c++ - 为什么字符串可以这样使用

Visual Studio 中的 C++ 文件扩展名

c++ - 对于矩阵乘积的 Cholesky, Eigen 和 C++11 类型推断失败

c++ - 通过 C++ 克隆 HDF5 文件的函数

c++ - 注入(inject) C++ DLL