捕获琐碎的Boost异常的奇怪问题 [英] Weird issue with catching trivial boost exception

查看:415
本文介绍了捕获琐碎的Boost异常的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下简单代码有疑问:

I have an issue with the following straightforward code:

    try
    {
        boost::lexical_cast<unsigned int>("invalid string");
    }
    catch(::boost::bad_lexical_cast &)
    {
        //It's not catched!!!
        return;
    }
    catch (std::exception &e){
        std::cerr << boost::diagnostic_information(e) << std::endl;

        ::boost::bad_lexical_cast s;
        std::string ss = typeid(s).name();
        std::cout << "'" << s.what()<<"': '"<< ss <<"'";

        std::string ee = typeid(e).name();
        std::cout << "'" << e.what()<<"': '"<< ee <<"'";
    }

boost :: bad_lexical_cast lexical_cast 抛出的c>异常与我尝试捕获的异常在某种程度上 不同,因此第一次捕获将被忽略。
一个异常的类型为:

The boost::bad_lexical_cast exception thrown by lexical_cast is somehow different than the one I try to catch, so the first catch is simply ignored. One exception is of type:

(被缠结)
N5boost16exception_detail10clone_implINS0_19error_info_injectorINS_16bad_lexical_castEEEEE

即是:

boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >

而另一个只是 boost :: bad_lexical_exception

我的问题是:如何更好地调试这种情况?为什么仅在本地发生而在其他环境中却没有出现该问题呢?我该如何防止这些怪异行为?

My question is: how can I better debug such a situation? Why does it happen only locally while n another environment the issue doesn't appear? And how can I prevent these weird behaviours?

感谢您的帮助!

推荐答案

您看到的怪异类型是 boost :: exception_detail :: clone_impl< boost :: exception_detail :: error_info_injector< boost :: bad_lexical_cast>> 。它是Boost.Exception提供的 bad_lexical_cast 的包装(并派生自该包装),它为 boost :: exception_ptr 提供支持和错误信息工具。

The weird type you see is a boost::exception_detail::clone_impl< boost::exception_detail::error_info_injector< boost::bad_lexical_cast>>. It's a wrapper around (and derived from) bad_lexical_cast provided by Boost.Exception, which provides support for boost::exception_ptr and the error info facilities. It should be caught just fine by the first catch.

否则,通常是在不同动态库中出现RTTI信息冲突的结果。这是我唯一可以解释的测试用例的行为。

When it isn't, that's usually an effect of conflicting RTTI information in different dynamic libraries. It's the only thing I can think of to explain the behavior of your test case.

这篇关于捕获琐碎的Boost异常的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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