嵌套异常和原始类型 [英] nested exceptions and primitive types
问题描述
当我捕获的异常是原始类型时,我可以使用 std :: throw_with_nested
吗?
Can I use std::throw_with_nested
when my captured exception is of primitive type?
,新类型从捕获的异常和新异常派生。但我不能从基本类型导出 int
。因此,我不能使用嵌套异常与原始类型。这是真的吗?
It is said, that the new type is derived from the captured exception and the new exception. But I can not derive from primitives types like int
. Therefore I can not use nested exceptions with primitive types. Is that true?
推荐答案
我的标准副本说:
18.8.6 / 7 投掷:如果 U
类类型不是从 U
和<$ c $公开派生的未指定类型的 nested_exception
c> cested> c> std :: forward< T>(t)
构造,否则 std :: forward< T> ;(t)
。
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 $ c>应该
throw 42;
这篇关于嵌套异常和原始类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!