forked from boostorg/exception
Merging from trunk: new function diagnostic_information_what, and mutable error info access.
[SVN r56477]
This commit is contained in:
@ -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.";
|
||||
}
|
||||
|
Reference in New Issue
Block a user