]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/exception/diagnostic_information.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
a46c266dc91593c1805a4f610e3b6296d43272e8
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / exception / diagnostic_information.hpp
1 //Copyright (c) 2006-2009 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 #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)\r
9 #pragma GCC system_header\r
10 #endif\r
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)\r
12 #pragma warning(push,1)\r
13 #endif\r
14 \r
15 #include <boost/config.hpp>\r
16 #include <boost/exception/get_error_info.hpp>\r
17 #include <boost/utility/enable_if.hpp>\r
18 #include <boost/config.hpp>\r
19 #include <exception>\r
20 #include <sstream>\r
21 #include <string>\r
22 \r
23 #ifndef BOOST_NO_EXCEPTIONS\r
24 #include <boost/exception/current_exception_cast.hpp>\r
25 namespace\r
26 boost\r
27     {\r
28     namespace\r
29     exception_detail\r
30         {\r
31         std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool );\r
32         }\r
33 \r
34     inline\r
35     std::string\r
36     current_exception_diagnostic_information()\r
37         {\r
38         boost::exception const * be=current_exception_cast<boost::exception const>();\r
39         std::exception const * se=current_exception_cast<std::exception const>();\r
40         if( be || se )\r
41             return exception_detail::diagnostic_information_impl(be,se,true);\r
42         else\r
43             return "No diagnostic information available.";\r
44         }\r
45     }\r
46 #endif\r
47 \r
48 namespace\r
49 boost\r
50     {\r
51     namespace\r
52     exception_detail\r
53         {\r
54         inline\r
55         exception const *\r
56         get_boost_exception( exception const * e )\r
57             {\r
58             return e;\r
59             }\r
60 \r
61         inline\r
62         exception const *\r
63         get_boost_exception( ... )\r
64             {\r
65             return 0;\r
66             }\r
67 \r
68         inline\r
69         std::exception const *\r
70         get_std_exception( std::exception const * e )\r
71             {\r
72             return e;\r
73             }\r
74 \r
75         inline\r
76         std::exception const *\r
77         get_std_exception( ... )\r
78             {\r
79             return 0;\r
80             }\r
81 \r
82         inline\r
83         char const *\r
84         get_diagnostic_information( exception const & x, char const * header )\r
85             {\r
86             if( error_info_container * c=x.data_.get() )\r
87 #ifndef BOOST_NO_EXCEPTIONS\r
88                 try\r
89                     {\r
90 #endif\r
91                     return c->diagnostic_information(header);\r
92 #ifndef BOOST_NO_EXCEPTIONS\r
93                     }\r
94                 catch(...)\r
95                     {\r
96                     }\r
97 #endif\r
98             return 0;\r
99             }\r
100 \r
101         inline\r
102         std::string\r
103         diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )\r
104             {\r
105             if( !be && !se )\r
106                 return "Unknown exception.";\r
107 #ifndef BOOST_NO_RTTI\r
108             if( !be )\r
109                 be=dynamic_cast<boost::exception const *>(se);\r
110             if( !se )\r
111                 se=dynamic_cast<std::exception const *>(be);\r
112 #endif\r
113             char const * wh=0;\r
114             if( with_what && se )\r
115                 {\r
116                 wh=se->what();\r
117                 if( be && exception_detail::get_diagnostic_information(*be,0)==wh )\r
118                     return wh;\r
119                 }\r
120             std::ostringstream tmp;\r
121             if( be )\r
122                 {\r
123                 if( char const * const * f=get_error_info<throw_file>(*be) )\r
124                     {\r
125                     tmp << *f;\r
126                     if( int const * l=get_error_info<throw_line>(*be) )\r
127                         tmp << '(' << *l << "): ";\r
128                     }\r
129                 tmp << "Throw in function ";\r
130                 if( char const * const * fn=get_error_info<throw_function>(*be) )\r
131                     tmp << *fn;\r
132                 else\r
133                     tmp << "(unknown)";\r
134                 tmp << '\n';\r
135                 }\r
136 #ifndef BOOST_NO_RTTI\r
137             tmp << std::string("Dynamic exception type: ") <<\r
138                 (be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).type_.name() << '\n';\r
139 #endif\r
140             if( with_what && se )\r
141                 tmp << "std::exception::what: " << wh << '\n';\r
142             if( be )\r
143                 if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )\r
144                     if( *s )\r
145                         return s;\r
146             return tmp.str();\r
147             }\r
148         }\r
149 \r
150     template <class T>\r
151     std::string\r
152     diagnostic_information( T const & e )\r
153         {\r
154         return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true);\r
155         }\r
156 \r
157     inline\r
158     char const *\r
159     diagnostic_information_what( exception const & e ) throw()\r
160         {\r
161         char const * w=0;\r
162 #ifndef BOOST_NO_EXCEPTIONS\r
163         try\r
164             {\r
165 #endif\r
166             (void) exception_detail::diagnostic_information_impl(&e,0,false);\r
167             return exception_detail::get_diagnostic_information(e,0);\r
168 #ifndef BOOST_NO_EXCEPTIONS\r
169             }\r
170         catch(\r
171         ... )\r
172             {\r
173             }\r
174 #endif\r
175         return w;\r
176         }\r
177     }\r
178 \r
179 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)\r
180 #pragma warning(pop)\r
181 #endif\r
182 #endif\r