New function: diagnostic_information_what.

[SVN r56448]
This commit is contained in:
Emil Dotchevski
2009-09-27 21:17:48 +00:00
parent 9683159e5c
commit c25d7d2ba0
12 changed files with 8429 additions and 8023 deletions

View File

@ -44,14 +44,14 @@ boost
inline
char const *
get_diagnostic_information( exception const & x )
get_diagnostic_information( exception const & x, char const * header )
{
if( error_info_container * c=x.data_.get() )
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
return c->diagnostic_information();
return c->diagnostic_information(header);
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
@ -63,7 +63,7 @@ boost
inline
std::string
diagnostic_information_impl( boost::exception const * be, std::exception const * se )
diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )
{
BOOST_ASSERT(be||se);
#ifndef BOOST_NO_RTTI
@ -72,6 +72,13 @@ boost
if( !be )
be = dynamic_cast<boost::exception const *>(se);
#endif
char const * wh=0;
if( with_what && se )
{
wh=se->what();
if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
return wh;
}
std::ostringstream tmp;
if( be )
{
@ -92,12 +99,12 @@ boost
tmp << std::string("Dynamic exception type: ") <<
(be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
#endif
if( se )
tmp << "std::exception::what: " << se->what() << '\n';
if( with_what && se )
tmp << "std::exception::what: " << wh << '\n';
if( be )
if( char const * s=exception_detail::get_diagnostic_information(*be) )
if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
if( *s )
tmp << s;
return s;
return tmp.str();
}
}
@ -107,7 +114,7 @@ boost
typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
diagnostic_information( T const & e )
{
return exception_detail::diagnostic_information_impl(&e,0);
return exception_detail::diagnostic_information_impl(&e,0,true);
}
template <class T>
@ -115,7 +122,28 @@ boost
typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
diagnostic_information( T const & e )
{
return exception_detail::diagnostic_information_impl(0,&e);
return exception_detail::diagnostic_information_impl(0,&e,true);
}
inline
char const *
diagnostic_information_what( exception const & e ) throw()
{
char const * w=0;
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
(void) exception_detail::diagnostic_information_impl(&e,0,false);
return exception_detail::get_diagnostic_information(e,0);
#ifndef BOOST_NO_EXCEPTIONS
}
catch(
... )
{
}
#endif
return w;
}
}
@ -131,7 +159,7 @@ boost
boost::exception const * be=current_exception_cast<boost::exception const>();
std::exception const * se=current_exception_cast<std::exception const>();
if( be || se )
return exception_detail::diagnostic_information_impl(be,se);
return exception_detail::diagnostic_information_impl(be,se,true);
else
return "No diagnostic information available.";
}

View File

@ -143,7 +143,7 @@ boost
struct
error_info_container
{
virtual char const * diagnostic_information() const = 0;
virtual char const * diagnostic_information( char const * ) const = 0;
virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
virtual void add_ref() const = 0;
@ -169,7 +169,7 @@ boost
template <>
struct get_info<throw_line>;
char const * get_diagnostic_information( exception const & );
char const * get_diagnostic_information( exception const &, char const * );
}
class
@ -231,7 +231,7 @@ boost
return x;
}
friend char const * exception_detail::get_diagnostic_information( exception const & );
friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
template <class E,class Tag,class T>
friend E const & operator<<( E const &, error_info<Tag,T> const & );

View File

@ -98,11 +98,13 @@ boost
}
char const *
diagnostic_information() const
diagnostic_information( char const * header ) const
{
if( diagnostic_info_str_.empty() )
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 )
{
shared_ptr<error_info_base const> const & x = i->second;