Im folgenden Code möchte ich die what()
Nachricht einer Boost :: Ausnahme erhalten.Erhalte die what() Nachricht von 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;
}
Wenn ich es laufen lasse, erhalte ich die Meldung:
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> >
Aber wenn ich nicht die Ausnahme abfangen, die Shell-Ausgänge:
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
Ich möchte diese Nachricht: bad lexical cast: source type value could not be interpreted as target
; aber ich konnte nicht den Weg finden, es zu haben. Das Boost-Exception-System ist mir ein Rätsel.
Wie bekomme ich diese Botschaft?
Bearbeiten: boost :: Ausnahme hat keine what()
Methode. Also, wie kann die Shell schreiben std::exception::what: bad lexical cast: source type value could not be interpreted as target
, da dies kein std::exception
ist?
anzeigen kann ich nicht ein starkes Argument finden mit boost ::Ausnahme. Ist es zu spät, um den Standard zu machen? http://en.cppreference.com/w/cpp/error/throw_with_nested –