【发布时间】:2018-06-29 15:32:58
【问题描述】:
这个问题很简单,但我不知道该怎么做。我想获取 system_error,然后从那里获取具体的错误代码。我在错误中有这样的东西:
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::current_exception_std_exception_wrapper<std::runtime_error> >
std::exception::what:
boost::system::system_error
我可以直接捕获boost::exception,但不能直接捕获std::runtime_error 或boost::system_error:
try {
this->service_.run();
}
catch (boost::system::system_error const & e) {
i_->playerLog->info("Exiting with system error. Error code: {} -- What: {}", e.code().value(),
e.what());
}
catch (boost::exception const & e) {
i_->playerLog->info("Exiting with boost exception: {}", boost::diagnostic_information(e));
}
我的代码将进入 boost::exception 子句,但不会进入 system_error 或 runtime_erro
【问题讨论】:
-
异常的根源是什么?
-
好问题...我猜它来自 boost.asio。不过代码相当复杂。
-
你怎么知道它不会捕获
std::runtime_error?我问只是因为显示的代码没有明确的catch子句。 -
@G.M.是的,它正在捕获
std::runtime_error,我刚刚尝试过。我想我可以 dynamic_cast 到 boost::system_error 并从那里解开。 -
可能会提供有用的信息以在成功捕获该事物的某些 catch 子句中打印出
typeid(e).name()。
标签: c++ boost exception-handling