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
9 #include <boost/config.hpp>
10 #include <boost/exception/get_error_info.hpp>
11 #include <boost/exception/info.hpp>
12 #include <boost/utility/enable_if.hpp>
14 #include <boost/core/demangle.hpp>
19 #ifndef BOOST_NO_EXCEPTIONS
20 #include <boost/exception/current_exception_cast.hpp>
23 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
24 #pragma GCC system_header
26 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
27 #pragma warning(push,1)
30 #ifndef BOOST_NO_EXCEPTIONS
37 std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool, bool );
42 current_exception_diagnostic_information( bool verbose=true)
44 boost::exception const * be=current_exception_cast<boost::exception const>();
45 std::exception const * se=current_exception_cast<std::exception const>();
47 return exception_detail::diagnostic_information_impl(be,se,true,verbose);
49 return "No diagnostic information available.";
62 get_boost_exception( exception const * e )
69 get_boost_exception( ... )
75 std::exception const *
76 get_std_exception( std::exception const * e )
82 std::exception const *
83 get_std_exception( ... )
90 get_diagnostic_information( exception const & x, char const * header )
92 #ifndef BOOST_NO_EXCEPTIONS
96 error_info_container * c=x.data_.get();
98 x.data_.adopt(c=new exception_detail::error_info_container_impl);
99 char const * di=c->diagnostic_information(header);
102 #ifndef BOOST_NO_EXCEPTIONS
113 diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what, bool verbose )
116 return "Unknown exception.";
117 #ifndef BOOST_NO_RTTI
119 be=dynamic_cast<boost::exception const *>(se);
121 se=dynamic_cast<std::exception const *>(be);
124 if( with_what && se )
127 if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
130 std::ostringstream tmp;
133 char const * const * f=get_error_info<throw_file>(*be);
134 int const * l=get_error_info<throw_line>(*be);
135 char const * const * fn=get_error_info<throw_function>(*be);
136 if( !f && !l && !fn )
137 tmp << "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
143 if( int const * l=get_error_info<throw_line>(*be) )
144 tmp << '(' << *l << "): ";
146 tmp << "Throw in function ";
147 if( char const * const * fn=get_error_info<throw_function>(*be) )
154 #ifndef BOOST_NO_RTTI
156 tmp << std::string("Dynamic exception type: ") <<
157 core::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
159 if( with_what && se && verbose )
160 tmp << "std::exception::what: " << wh << '\n';
162 if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
164 return std::string(s);
171 diagnostic_information( T const & e, bool verbose=true )
173 return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true,verbose);
178 diagnostic_information_what( exception const & e, bool verbose=true ) throw()
181 #ifndef BOOST_NO_EXCEPTIONS
185 (void) exception_detail::diagnostic_information_impl(&e,0,false,verbose);
186 if( char const * di=exception_detail::get_diagnostic_information(e,0) )
189 return "Failed to produce boost::diagnostic_information_what()";
190 #ifndef BOOST_NO_EXCEPTIONS
201 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)