1 //Copyright (c) 2006-2010 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
8 #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
9 #pragma GCC system_header
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
12 #pragma warning(push,1)
15 #include <boost/config.hpp>
16 #include <boost/exception/get_error_info.hpp>
17 #include <boost/exception/info.hpp>
18 #include <boost/utility/enable_if.hpp>
20 #include <boost/units/detail/utility.hpp>
26 #ifndef BOOST_NO_EXCEPTIONS
27 #include <boost/exception/current_exception_cast.hpp>
34 std::string
diagnostic_information_impl( boost::exception
const *, std::exception
const *, bool );
39 current_exception_diagnostic_information()
41 boost::exception
const * be
=current_exception_cast
<boost::exception
const>();
42 std::exception
const * se
=current_exception_cast
<std::exception
const>();
44 return exception_detail::diagnostic_information_impl(be
,se
,true);
46 return "No diagnostic information available.";
59 get_boost_exception( exception
const * e
)
66 get_boost_exception( ... )
72 std::exception
const *
73 get_std_exception( std::exception
const * e
)
79 std::exception
const *
80 get_std_exception( ... )
87 get_diagnostic_information( exception
const & x
, char const * header
)
89 #ifndef BOOST_NO_EXCEPTIONS
93 error_info_container
* c
=x
.data_
.get();
95 x
.data_
.adopt(c
=new exception_detail::error_info_container_impl
);
96 char const * di
=c
->diagnostic_information(header
);
99 #ifndef BOOST_NO_EXCEPTIONS
110 diagnostic_information_impl( boost::exception
const * be
, std::exception
const * se
, bool with_what
)
113 return "Unknown exception.";
114 #ifndef BOOST_NO_RTTI
116 be
=dynamic_cast<boost::exception
const *>(se
);
118 se
=dynamic_cast<std::exception
const *>(be
);
121 if( with_what
&& se
)
124 if( be
&& exception_detail::get_diagnostic_information(*be
,0)==wh
)
127 std::ostringstream tmp
;
130 char const * const * f
=get_error_info
<throw_file
>(*be
);
131 int const * l
=get_error_info
<throw_line
>(*be
);
132 char const * const * fn
=get_error_info
<throw_function
>(*be
);
133 if( !f
&& !l
&& !fn
)
134 tmp
<< "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
140 if( int const * l
=get_error_info
<throw_line
>(*be
) )
141 tmp
<< '(' << *l
<< "): ";
143 tmp
<< "Throw in function ";
144 if( char const * const * fn
=get_error_info
<throw_function
>(*be
) )
151 #ifndef BOOST_NO_RTTI
152 tmp
<< std::string("Dynamic exception type: ") <<
153 units::detail::demangle((be
?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be
)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se
))).type_
->name()) << '\n';
155 if( with_what
&& se
)
156 tmp
<< "std::exception::what: " << wh
<< '\n';
158 if( char const * s
=exception_detail::get_diagnostic_information(*be
,tmp
.str().c_str()) )
167 diagnostic_information( T
const & e
)
169 return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e
),exception_detail::get_std_exception(&e
),true);
174 diagnostic_information_what( exception
const & e
) throw()
177 #ifndef BOOST_NO_EXCEPTIONS
181 (void) exception_detail::diagnostic_information_impl(&e
,0,false);
182 if( char const * di
=exception_detail::get_diagnostic_information(e
,0) )
185 return "Failed to produce boost::diagnostic_information_what()";
186 #ifndef BOOST_NO_EXCEPTIONS
197 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)