1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef UUID_0552D49838DD11DD90146B8956D89593
7 #define UUID_0552D49838DD11DD90146B8956D89593
9 #include <boost/config.hpp>
10 #include <boost/exception/get_error_info.hpp>
11 #include <boost/utility/enable_if.hpp>
24 enable_boost_exception_overload
26 struct yes { char q[100]; };
28 static yes check(exception const *);
30 enum e { value=sizeof(check((T*)0))==sizeof(yes) };
35 enable_std_exception_overload
37 struct yes { char q[100]; };
39 static yes check(std::exception const *);
41 enum e { value = !enable_boost_exception_overload<T>::value && sizeof(check((T*)0))==sizeof(yes) };
48 dynamic_exception_type( T const & x )
50 return std::string("Dynamic exception type: ") + BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
56 get_diagnostic_information( exception const & x )
58 if( error_info_container * c=x.data_.get() )
59 #ifndef BOOST_NO_EXCEPTIONS
63 return c->diagnostic_information();
64 #ifndef BOOST_NO_EXCEPTIONS
75 boost_diagnostic_information( exception const & x )
77 std::ostringstream tmp;
78 if( char const * const * f=get_error_info<throw_file>(x) )
81 if( int const * l=get_error_info<throw_line>(x) )
82 tmp << '(' << *l << "): ";
84 tmp << "Throw in function ";
85 if( char const * const * fn=get_error_info<throw_function>(x) )
91 tmp << dynamic_exception_type(x) << std::endl;
92 if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
93 tmp << "std::exception::what: " << e->what() << std::endl;
95 if( char const * s=exception_detail::get_diagnostic_information(x) )
103 std_diagnostic_information( std::exception const & x )
105 std::ostringstream tmp;
106 #ifndef BOOST_NO_RTTI
107 if( exception const * e=dynamic_cast<exception const *>(&x) )
108 return boost_diagnostic_information(*e);
109 tmp << dynamic_exception_type(x) << std::endl;
111 tmp << "std::exception::what: " << x.what() << std::endl;
118 typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
119 diagnostic_information( T const & e )
121 return exception_detail::boost_diagnostic_information(e);
126 typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
127 diagnostic_information( T const & e )
129 return exception_detail::std_diagnostic_information(e);
133 #ifndef BOOST_NO_EXCEPTIONS
134 #include <boost/exception/current_exception_cast.hpp>
140 current_exception_diagnostic_information()
142 if( boost::exception const * e=current_exception_cast<boost::exception const>() )
143 return diagnostic_information(*e);
144 else if( std::exception const * e=current_exception_cast<std::exception const>() )
145 return diagnostic_information(*e);
147 return "No diagnostic information available.";