2009-04-07 03:02:15 +00:00
|
|
|
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
|
2008-06-25 23:27:56 +00:00
|
|
|
|
|
|
|
//Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
#ifndef UUID_0552D49838DD11DD90146B8956D89593
|
|
|
|
#define UUID_0552D49838DD11DD90146B8956D89593
|
|
|
|
|
2009-01-30 00:06:01 +00:00
|
|
|
#include <boost/config.hpp>
|
2008-09-01 21:06:09 +00:00
|
|
|
#include <boost/exception/get_error_info.hpp>
|
2009-05-15 22:34:30 +00:00
|
|
|
#include <boost/exception/detail/exception_ptr_base.hpp>
|
2009-04-06 23:15:42 +00:00
|
|
|
#include <boost/utility/enable_if.hpp>
|
2008-06-25 23:27:56 +00:00
|
|
|
#include <exception>
|
2008-09-01 21:06:09 +00:00
|
|
|
#include <sstream>
|
2008-06-25 23:27:56 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
boost
|
|
|
|
{
|
2008-08-30 02:57:12 +00:00
|
|
|
namespace
|
|
|
|
exception_detail
|
|
|
|
{
|
2009-04-06 23:15:42 +00:00
|
|
|
template <class T>
|
|
|
|
struct
|
|
|
|
enable_boost_exception_overload
|
|
|
|
{
|
2009-04-12 17:21:39 +00:00
|
|
|
struct yes { char q[100]; };
|
2009-04-06 23:15:42 +00:00
|
|
|
typedef char no;
|
|
|
|
static yes check(exception const *);
|
|
|
|
static no check(...);
|
|
|
|
enum e { value=sizeof(check((T*)0))==sizeof(yes) };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct
|
|
|
|
enable_std_exception_overload
|
|
|
|
{
|
2009-04-12 17:21:39 +00:00
|
|
|
struct yes { char q[100]; };
|
2009-04-06 23:15:42 +00:00
|
|
|
typedef char no;
|
|
|
|
static yes check(std::exception const *);
|
|
|
|
static no check(...);
|
|
|
|
enum e { value = !enable_boost_exception_overload<T>::value && sizeof(check((T*)0))==sizeof(yes) };
|
|
|
|
};
|
|
|
|
|
2008-09-03 02:14:27 +00:00
|
|
|
inline
|
2008-09-01 21:06:09 +00:00
|
|
|
char const *
|
|
|
|
get_diagnostic_information( exception const & x )
|
|
|
|
{
|
|
|
|
if( error_info_container * c=x.data_.get() )
|
2009-01-30 00:06:01 +00:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2008-09-01 21:06:09 +00:00
|
|
|
try
|
|
|
|
{
|
2009-01-30 00:06:01 +00:00
|
|
|
#endif
|
2008-09-01 21:06:09 +00:00
|
|
|
return c->diagnostic_information();
|
2009-01-30 00:06:01 +00:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2008-09-01 21:06:09 +00:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
}
|
2009-01-30 00:06:01 +00:00
|
|
|
#endif
|
2008-09-01 21:06:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-04-06 23:15:42 +00:00
|
|
|
|
|
|
|
inline
|
|
|
|
std::string
|
2009-05-15 22:34:30 +00:00
|
|
|
diagnostic_information_impl( boost::exception const * be, std::exception const * se )
|
2009-04-06 23:15:42 +00:00
|
|
|
{
|
2009-05-15 22:34:30 +00:00
|
|
|
BOOST_ASSERT(be||se);
|
2009-04-06 23:15:42 +00:00
|
|
|
#ifndef BOOST_NO_RTTI
|
2009-05-15 22:34:30 +00:00
|
|
|
if( !se )
|
|
|
|
se = dynamic_cast<std::exception const *>(be);
|
|
|
|
if( !be )
|
|
|
|
be = dynamic_cast<boost::exception const *>(se);
|
2009-04-06 23:15:42 +00:00
|
|
|
#endif
|
|
|
|
std::ostringstream tmp;
|
2009-05-15 22:34:30 +00:00
|
|
|
if( be )
|
|
|
|
{
|
|
|
|
if( char const * const * f=get_error_info<throw_file>(*be) )
|
|
|
|
{
|
|
|
|
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';
|
|
|
|
}
|
2009-04-06 23:15:42 +00:00
|
|
|
#ifndef BOOST_NO_RTTI
|
2009-05-15 22:34:30 +00:00
|
|
|
tmp << std::string("Dynamic exception type: ") <<
|
|
|
|
(be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
|
2009-04-06 23:15:42 +00:00
|
|
|
#endif
|
2009-05-15 22:34:30 +00:00
|
|
|
if( se )
|
|
|
|
tmp << "std::exception::what: " << se->what() << '\n';
|
|
|
|
if( be )
|
|
|
|
if( char const * s=exception_detail::get_diagnostic_information(*be) )
|
|
|
|
if( *s )
|
|
|
|
tmp << s;
|
2009-04-06 23:15:42 +00:00
|
|
|
return tmp.str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline
|
|
|
|
typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
|
|
|
|
diagnostic_information( T const & e )
|
|
|
|
{
|
2009-05-15 22:34:30 +00:00
|
|
|
return exception_detail::diagnostic_information_impl(&e,0);
|
2009-04-06 23:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline
|
|
|
|
typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
|
|
|
|
diagnostic_information( T const & e )
|
|
|
|
{
|
2009-05-15 22:34:30 +00:00
|
|
|
return exception_detail::diagnostic_information_impl(0,&e);
|
2008-08-30 02:57:12 +00:00
|
|
|
}
|
2009-04-08 19:20:35 +00:00
|
|
|
}
|
2008-08-30 02:57:12 +00:00
|
|
|
|
2009-04-08 19:20:35 +00:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
#include <boost/exception/current_exception_cast.hpp>
|
|
|
|
namespace
|
|
|
|
boost
|
|
|
|
{
|
2008-06-25 23:27:56 +00:00
|
|
|
inline
|
|
|
|
std::string
|
2009-04-06 23:15:42 +00:00
|
|
|
current_exception_diagnostic_information()
|
2008-06-25 23:27:56 +00:00
|
|
|
{
|
2009-05-15 22:34:30 +00:00
|
|
|
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);
|
2008-09-05 03:15:18 +00:00
|
|
|
else
|
2009-04-06 23:15:42 +00:00
|
|
|
return "No diagnostic information available.";
|
2008-06-25 23:27:56 +00:00
|
|
|
}
|
2009-05-15 22:34:30 +00:00
|
|
|
|
|
|
|
inline
|
|
|
|
std::string
|
|
|
|
diagnostic_information( exception_detail::exception_ptr_base const & p )
|
|
|
|
{
|
|
|
|
if( !p._empty() )
|
|
|
|
try
|
|
|
|
{
|
|
|
|
p._rethrow();
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
return current_exception_diagnostic_information();
|
|
|
|
}
|
|
|
|
return "<empty>";
|
|
|
|
}
|
|
|
|
}
|
2009-04-08 19:20:35 +00:00
|
|
|
#endif
|
2008-06-25 23:27:56 +00:00
|
|
|
|
|
|
|
#endif
|