Merge c:/dyninst/pc_bluegene/dyninst into dyn_pc_integration
[dyninst.git] / external / boost / exception / diagnostic_information.hpp
1 //Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
2
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)
5
6 #ifndef UUID_0552D49838DD11DD90146B8956D89593
7 #define UUID_0552D49838DD11DD90146B8956D89593
8
9 #include <boost/exception/get_error_info.hpp>
10 #include <exception>
11 #include <sstream>
12 #include <string>
13
14 namespace
15 boost
16     {
17     namespace
18     exception_detail
19         {
20         inline
21         char const *
22         get_diagnostic_information( exception const & x )
23             {
24             if( error_info_container * c=x.data_.get() )
25                 try
26                     {
27                     return c->diagnostic_information();
28                     }
29                 catch(...)
30                     {
31                     }
32             return 0;
33             }
34         }
35
36     inline
37     std::string
38     diagnostic_information( exception const & x )
39         {
40         std::ostringstream tmp;
41         if( boost::shared_ptr<char const * const> f=get_error_info<throw_file>(x) )
42             {
43             tmp << *f;
44             if( boost::shared_ptr<int const> l=get_error_info<throw_line>(x) )
45                 tmp << '(' << *l << "): ";
46             }
47         tmp << "Throw in function ";
48         if( boost::shared_ptr<char const * const> fn=get_error_info<throw_function>(x) )
49             tmp << *fn;
50         else
51             tmp << "(unknown)";
52 #ifndef BOOST_NO_RTTI
53         tmp << "\nDynamic exception type: " << BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
54         if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
55             tmp << "\nstd::exception::what: " << e->what();
56 #endif
57         if( char const * s=exception_detail::get_diagnostic_information(x) )
58             if( *s )
59                 tmp << '\n' << s;
60         return tmp.str();
61         }
62     }
63
64 #endif