Nel seguente codice, voglio ottenere il messaggio what()
di un boost :: exception.Ottieni il messaggio what() di 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;
}
quando l'eseguo, ottengo il messaggio:
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> >
Ma quando io non intercettare l'eccezione, le uscite di shell:
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
voglio che un messaggio: bad lexical cast: source type value could not be interpreted as target
; ma non sono riuscito a trovare il modo di averlo Il sistema di eccezioni boost è un mistero per me.
Come ottenere questo stesso messaggio?
Modifica: boost :: l'eccezione non ha il metodo what()
. Quindi, come può scrivere la shell std::exception::what: bad lexical cast: source type value could not be interpreted as target
, poiché questo non è un std::exception
?
dopo l'avvento di C++ 11 di eccezioni nidificate non riesco a trovare una forte necessità di usare il boost ::eccezione. è troppo tardi per farlo nel modo standard? http://en.cppreference.com/w/cpp/error/throw_with_nested –