【发布时间】:2010-11-06 12:28:55
【问题描述】:
所有 boost 异常都源自 std::exception 吗?如果不是,它们是否都派生自某个基本异常类?
【问题讨论】:
标签: c++ exception boost exception-handling
所有 boost 异常都源自 std::exception 吗?如果不是,它们是否都派生自某个基本异常类?
【问题讨论】:
标签: c++ exception boost exception-handling
【讨论】:
boost::exception 不继承自std::exception。
“良好的 Boost 公民”库应使用 boost::throw_exception 抛出,以支持禁用异常处理的配置。
boost::throw_exception 函数要求传递的异常的类型公开地从 std::exception 派生(从版本 1.37.0 起,如果不满足该要求,boost::throw_exception 将发出编译错误。)此外,默认情况下,使用boost::throw_exception 发出的异常派生自boost::exception。
但是,Boost 库不需要通过boost:throw_exception 抛出异常或从std::exception 派生。
【讨论】:
我相信是的。想不出一个 boost 库会抛出基于非 std::exception 的东西。
【讨论】: