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, char const * header )
49 if( error_info_container * c=x.data_.get() )
50 #ifndef BOOST_NO_EXCEPTIONS
54 return c->diagnostic_information(header);
55 #ifndef BOOST_NO_EXCEPTIONS
66 diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )
71 se = dynamic_cast<std::exception const *>(be);
73 be = dynamic_cast<boost::exception const *>(se);
79 if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
82 std::ostringstream tmp;
85 if( char const * const * f=get_error_info<throw_file>(*be) )
88 if( int const * l=get_error_info<throw_line>(*be) )
89 tmp << '(' << *l << "): ";
91 tmp << "Throw in function ";
92 if( char const * const * fn=get_error_info<throw_function>(*be) )
99 tmp << std::string("Dynamic exception type: ") <<
100 (be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
102 if( with_what && se )
103 tmp << "std::exception::what: " << wh << '\n';
105 if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
114 typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
115 diagnostic_information( T const & e )
117 return exception_detail::diagnostic_information_impl(&e,0,true);
122 typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
123 diagnostic_information( T const & e )
125 return exception_detail::diagnostic_information_impl(0,&e,true);
130 diagnostic_information_what( exception const & e ) throw()
133 #ifndef BOOST_NO_EXCEPTIONS
137 (void) exception_detail::diagnostic_information_impl(&e,0,false);
138 return exception_detail::get_diagnostic_information(e,0);
139 #ifndef BOOST_NO_EXCEPTIONS
150 #ifndef BOOST_NO_EXCEPTIONS
151 #include <boost/exception/current_exception_cast.hpp>
157 current_exception_diagnostic_information()
159 boost::exception const * be=current_exception_cast<boost::exception const>();
160 std::exception const * se=current_exception_cast<std::exception const>();
162 return exception_detail::diagnostic_information_impl(be,se,true);
164 return "No diagnostic information available.";
169 diagnostic_information( exception_detail::exception_ptr_base const & p )
179 return current_exception_diagnostic_information();