[lexical_cast] lexical_cast does not throw bad_lexical_cast

Hi, I've noticed that sometimes lexical_cast does not throw bad_lexical_cast. Instead, it throws 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast>
'. A catch clause expecting a bad_lexical_cast fails here.
What seems confusing to me is that the lexical_cast docs do mention "catch (bad_lexical_cast &)" as correct code (http://www.boost.org/doc/libs/1_39_0/libs/conversion/lexical_cast.htm). The solution that worked for me was to catch boost::exception instead. Am I missing something here? I consulted the documentation, but still have no answer. It also seems that I am not alone with this problem; http://www.nabble.com/Porting-from-boost_1_33-to-boost_1_36-exception-td1970... and http://archives.free.net.ph/message/20090715.183116.374b4777.en.html at least indicate this for me. regards, Carlos Rafael Giani

AMDG Carlos Rafael Giani wrote:
I've noticed that sometimes lexical_cast does not throw bad_lexical_cast. Instead, it throws 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast>
'. A catch clause expecting a bad_lexical_cast fails here.
This type ought to inherit from boost::bad_lexical_cast, so you should be able to catch bad_lexical_cast.
What seems confusing to me is that the lexical_cast docs do mention "catch (bad_lexical_cast &)" as correct code (http://www.boost.org/doc/libs/1_39_0/libs/conversion/lexical_cast.htm). The solution that worked for me was to catch boost::exception instead.
Am I missing something here? I consulted the documentation, but still have no answer. It also seems that I am not alone with this problem;
http://www.nabble.com/Porting-from-boost_1_33-to-boost_1_36-exception-td1970... and http://archives.free.net.ph/message/20090715.183116.374b4777.en.html
at least indicate this for me.
It works for me with msvc 9.0. Do you have a test case? #include <boost/lexical_cast.hpp> #include <iostream> int main() { try { int i = boost::lexical_cast<int>("123ee"); } catch(boost::bad_lexical_cast&) { std::cout << "okay" << std::endl; } catch(...) { std::cout << "???" << std::endl; } } In Christ, Steven Watanabe
participants (2)
-
Carlos Rafael Giani
-
Steven Watanabe