当我捕获的异常是原始类型时,我可以使用 std::throw_with_nested
吗?
据说,新类型是从捕获的异常和新的异常中派生出来的。但我无法从 int
等原始类型派生。因此我不能对原始类型使用嵌套异常。是真的吗?
最佳答案
我的标准拷贝是这样说的:
18.8.6/7 Throws: if
U
is a non-union class type not derived fromnested_exception
, an exception of unspecified type that is publicly derived from bothU
andnested_exception
and constructed fromstd::forward<T>(t)
, otherwisestd::forward<T>(t)
.
所以 throw_with_nested(42)
应该throw 42;
关于c++ - 嵌套异常和原始类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22002331/