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 <<"'";
}
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:
(mangled)
N5boost16exception_detail10clone_implINS0_19error_info_injectorINS_16bad_lexical_castEEEEE
that is a:
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >
while the other one simply 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?
Thank for your help!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With