Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71158 - in branches/release: boost/exception libs/exception/test
From: emil_at_[hidden]
Date: 2011-04-09 22:13:12


Author: emildotchevski
Date: 2011-04-09 22:13:12 EDT (Sat, 09 Apr 2011)
New Revision: 71158
URL: http://svn.boost.org/trac/boost/changeset/71158

Log:
merged changes from trunk: better boost::diagnostic_information
Text files modified:
   branches/release/boost/exception/diagnostic_information.hpp | 56 +++++++++++++++++++++++++--------------
   branches/release/boost/exception/info.hpp | 1
   branches/release/libs/exception/test/diagnostic_information_test.cpp | 11 +++++++
   3 files changed, 47 insertions(+), 21 deletions(-)

Modified: branches/release/boost/exception/diagnostic_information.hpp
==============================================================================
--- branches/release/boost/exception/diagnostic_information.hpp (original)
+++ branches/release/boost/exception/diagnostic_information.hpp 2011-04-09 22:13:12 EDT (Sat, 09 Apr 2011)
@@ -14,6 +14,7 @@
 
 #include <boost/config.hpp>
 #include <boost/exception/get_error_info.hpp>
+#include <boost/exception/info.hpp>
 #include <boost/utility/enable_if.hpp>
 #ifndef BOOST_NO_RTTI
 #include <boost/units/detail/utility.hpp>
@@ -85,19 +86,23 @@
         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
@@ -122,18 +127,26 @@
             std::ostringstream tmp;
             if( be )
                 {
- if( char const * const * f=get_error_info<throw_file>(*be) )
+ char const * const * f=get_error_info<throw_file>(*be);
+ int const * l=get_error_info<throw_line>(*be);
+ char const * const * fn=get_error_info<throw_function>(*be);
+ if( !f && !l && !fn )
+ tmp << "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
+ else
                     {
- tmp << *f;
- if( int const * l=get_error_info<throw_line>(*be) )
- tmp << '(' << *l << "): ";
+ if( f )
+ {
+ tmp << *f;
+ if( int const * l=get_error_info<throw_line>(*be) )
+ tmp << '(' << *l << "): ";
+ }
+ tmp << "Throw in function ";
+ if( char const * const * fn=get_error_info<throw_function>(*be) )
+ tmp << *fn;
+ else
+ tmp << "(unknown)";
+ tmp << '\n';
                     }
- tmp << "Throw in function ";
- if( char const * const * fn=get_error_info<throw_function>(*be) )
- tmp << *fn;
- else
- tmp << "(unknown)";
- tmp << '\n';
                 }
 #ifndef BOOST_NO_RTTI
             tmp << std::string("Dynamic exception type: ") <<
@@ -166,7 +179,10 @@
             {
 #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(

Modified: branches/release/boost/exception/info.hpp
==============================================================================
--- branches/release/boost/exception/info.hpp (original)
+++ branches/release/boost/exception/info.hpp 2011-04-09 22:13:12 EDT (Sat, 09 Apr 2011)
@@ -109,7 +109,6 @@
                 {
                 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 )

Modified: branches/release/libs/exception/test/diagnostic_information_test.cpp
==============================================================================
--- branches/release/libs/exception/test/diagnostic_information_test.cpp (original)
+++ branches/release/libs/exception/test/diagnostic_information_test.cpp 2011-04-09 22:13:12 EDT (Sat, 09 Apr 2011)
@@ -202,6 +202,17 @@
         }
     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);
         throw x;
         }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk