Boost Exception major refactoring: works with or without RTTI, vastly improved boost::throw_exception integration.

[SVN r48905]
This commit is contained in:
Emil Dotchevski
2008-09-19 20:29:26 +00:00
parent c9fcdf15b2
commit a9b5723d0d
73 changed files with 6532 additions and 5046 deletions

View File

@ -6,21 +6,58 @@
#ifndef UUID_0552D49838DD11DD90146B8956D89593
#define UUID_0552D49838DD11DD90146B8956D89593
#include <boost/exception/exception.hpp>
#include <boost/exception/get_error_info.hpp>
#include <exception>
#include <sstream>
#include <string>
namespace
boost
{
namespace
exception_detail
{
inline
char const *
get_diagnostic_information( exception const & x )
{
if( error_info_container * c=x.data_.get() )
try
{
return c->diagnostic_information();
}
catch(...)
{
}
return 0;
}
}
inline
std::string
diagnostic_information( std::exception const & x )
diagnostic_information( exception const & x )
{
if( exception const * be = dynamic_cast<exception const *>(&x) )
return be->diagnostic_information();
std::ostringstream tmp;
if( boost::shared_ptr<char const * const> f=get_error_info<throw_file>(x) )
{
tmp << *f;
if( boost::shared_ptr<int const> l=get_error_info<throw_line>(x) )
tmp << '(' << *l << "): ";
}
tmp << "Throw in function ";
if( boost::shared_ptr<char const * const> fn=get_error_info<throw_function>(x) )
tmp << *fn;
else
return std::string("[ what: ") + x.what() + ", type: " + typeid(x).name() + " ]";
tmp << "(unknown)";
#ifndef BOOST_NO_RTTI
tmp << "\nDynamic exception type: " << BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
tmp << "\nstd::exception::what: " << e->what();
#endif
if( char const * s=exception_detail::get_diagnostic_information(x) )
if( *s )
tmp << '\n' << s;
return tmp.str();
}
}