diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp index 7cbb355..2a14438 100644 --- a/include/boost/exception/diagnostic_information.hpp +++ b/include/boost/exception/diagnostic_information.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #ifndef BOOST_NO_RTTI #include @@ -85,19 +86,23 @@ boost char const * get_diagnostic_information( exception const & x, char const * header ) { - if( error_info_container * c=x.data_.get() ) #ifndef BOOST_NO_EXCEPTIONS - try - { + try + { #endif - return c->diagnostic_information(header); + error_info_container * c=x.data_.get(); + if( !c ) + x.data_.adopt(c=new exception_detail::error_info_container_impl); + char const * di=c->diagnostic_information(header); + BOOST_ASSERT(di!=0); + return di; #ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - } + } + catch(...) + { + return 0; + } #endif - return 0; } inline @@ -166,7 +171,10 @@ boost { #endif (void) exception_detail::diagnostic_information_impl(&e,0,false); - return exception_detail::get_diagnostic_information(e,0); + if( char const * di=exception_detail::get_diagnostic_information(e,0) ) + return di; + else + return "Failed to produce boost::diagnostic_information_what()"; #ifndef BOOST_NO_EXCEPTIONS } catch( diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp index c918dbd..5530746 100644 --- a/include/boost/exception/info.hpp +++ b/include/boost/exception/info.hpp @@ -109,7 +109,6 @@ boost { if( header ) { - BOOST_ASSERT(*header!=0); std::ostringstream tmp; tmp << header; for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i ) diff --git a/test/diagnostic_information_test.cpp b/test/diagnostic_information_test.cpp index 8ced6e3..85e8a67 100644 --- a/test/diagnostic_information_test.cpp +++ b/test/diagnostic_information_test.cpp @@ -200,6 +200,17 @@ main() std::string di=current_exception_diagnostic_information(); test3(di); } + try + { + throw error4(); + } + catch( + error4 & x ) + { + std::string di1=boost::diagnostic_information(x); + std::string wh1=x.what(); + BOOST_TEST(wh1==di1); + } try { error4 x; x << tagged_int1(42) << tagged_int2(42);