In the following code, I want to receive the what() message of boost exception ::
#include <iostream> #include <boost/lexical_cast.hpp> #include <boost/exception/diagnostic_information.hpp> int main(void) { try { int i(boost::lexical_cast<int>("42X")); } catch (boost::exception const &e) { std::cout << "Exception: " << boost::diagnostic_information_what(e) << "\n"; } return 0; }
When I run it, I get a message:
Exception: Throw location unknown (consider using BOOST_THROW_EXCEPTION) Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >
But when I do not catch the exception, the shell output:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >' what(): bad lexical cast: source type value could not be interpreted as target [1] 8744 abort ./a.out
I want this message: bad lexical cast: source type value could not be interpreted as target ; but I could not find a way to get it. Forcing exclusion is a mystery to me.
How to receive this message?
Edit: boost :: exception does not have a what() method. So, how can a shell write std::exception::what: bad lexical cast: source type value could not be interpreted as target , since it is not std::exception ?
source share