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/exception/detail/exception_ptr_base.hpp>
12 #include <boost/utility/enable_if.hpp>
25 enable_boost_exception_overload
27 struct yes { char q[100]; };
29 static yes check(exception const *);
31 enum e { value=sizeof(check((T*)0))==sizeof(yes) };
36 enable_std_exception_overload
38 struct yes { char q[100]; };
40 static yes check(std::exception const *);
42 enum e { value = !enable_boost_exception_overload<T>::value && sizeof(check((T*)0))==sizeof(yes) };
47 get_diagnostic_information( exception const & x )
49 if( error_info_container * c=x.data_.get() )
50 #ifndef BOOST_NO_EXCEPTIONS
54 return c->diagnostic_information();
55 #ifndef BOOST_NO_EXCEPTIONS
66 diagnostic_information_impl( boost::exception const * be, std::exception const * se )
71 se = dynamic_cast<std::exception const *>(be);
73 be = dynamic_cast<boost::exception const *>(se);
75 std::ostringstream tmp;
78 if( char const * const * f=get_error_info<throw_file>(*be) )
81 if( int const * l=get_error_info<throw_line>(*be) )
82 tmp << '(' << *l << "): ";
84 tmp << "Throw in function ";
85 if( char const * const * fn=get_error_info<throw_function>(*be) )
92 tmp << std::string("Dynamic exception type: ") <<
93 (be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
96 tmp << "std::exception::what: " << se->what() << '\n';
98 if( char const * s=exception_detail::get_diagnostic_information(*be) )
107 typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
108 diagnostic_information( T const & e )
110 return exception_detail::diagnostic_information_impl(&e,0);
115 typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
116 diagnostic_information( T const & e )
118 return exception_detail::diagnostic_information_impl(0,&e);
122 #ifndef BOOST_NO_EXCEPTIONS
123 #include <boost/exception/current_exception_cast.hpp>
129 current_exception_diagnostic_information()
131 boost::exception const * be=current_exception_cast<boost::exception const>();
132 std::exception const * se=current_exception_cast<std::exception const>();
134 return exception_detail::diagnostic_information_impl(be,se);
136 return "No diagnostic information available.";
141 diagnostic_information( exception_detail::exception_ptr_base const & p )
151 return current_exception_diagnostic_information();