嵌套异常和原始类型 [英] nested exceptions and primitive types

查看:112
本文介绍了嵌套异常和原始类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我捕获的异常是原始类型时,我可以使用 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> cested> c> nested_exception 并从 std :: forward< T>(t)构造,否则 std :: forward< T> ;(t)

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 $ c>应该 throw 42;

这篇关于嵌套异常和原始类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆