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