gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:48:26 25 4
gpt4 key购买 nike

当我捕获的异常是原始类型时,我可以使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com