1 //Copyright (c) 2006-2009 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_618474C2DE1511DEB74A388C56D89593
7 #define UUID_618474C2DE1511DEB74A388C56D89593
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 #ifdef BOOST_NO_EXCEPTIONS
17 #error This header requires exception handling to be enabled.
19 #include <boost/exception/exception.hpp>
20 #include <boost/exception/info.hpp>
21 #include <boost/exception/diagnostic_information.hpp>
22 #include <boost/exception/detail/type_info.hpp>
23 #include <boost/shared_ptr.hpp>
31 typedef shared_ptr<exception_detail::clone_base const> exception_ptr;
33 exception_ptr current_exception();
38 copy_exception( T const & e )
42 throw enable_current_exception(e);
47 return current_exception();
52 typedef error_info<struct tag_original_exception_type,std::type_info const *> original_exception_type;
56 to_string( original_exception_type const & x )
58 return x.value()->name();
77 exception_detail::clone_impl<bad_alloc_> c(ba);
79 throw_function(BOOST_CURRENT_FUNCTION) <<
80 throw_file(__FILE__) <<
82 static exception_ptr ep(new exception_detail::clone_impl<bad_alloc_>(c));
88 exception_ptr_bad_alloc
90 static exception_ptr const e;
95 exception_ptr_bad_alloc<Dummy>::
96 e = get_bad_alloc<Dummy>();
101 public boost::exception,
102 public std::exception
111 unknown_exception( std::exception const & e )
113 add_original_type(e);
117 unknown_exception( boost::exception const & e ):
120 add_original_type(e);
123 ~unknown_exception() throw()
131 add_original_type( E const & e )
133 #ifndef BOOST_NO_RTTI
134 (*this) << original_exception_type(&typeid(e));
144 current_exception_std_exception_wrapper:
146 public boost::exception
151 current_exception_std_exception_wrapper( T const & e1 ):
154 add_original_type(e1);
157 current_exception_std_exception_wrapper( T const & e1, boost::exception const & e2 ):
161 add_original_type(e1);
164 ~current_exception_std_exception_wrapper() throw()
172 add_original_type( E const & e )
174 #ifndef BOOST_NO_RTTI
175 (*this) << original_exception_type(&typeid(e));
182 boost::exception const *
183 get_boost_exception( T const * )
190 boost::exception & x )
201 boost::exception const *
202 get_boost_exception( T const * x )
204 return dynamic_cast<boost::exception const *>(x);
211 current_exception_std_exception( T const & e1 )
213 if( boost::exception const * e2 = get_boost_exception(&e1) )
214 return boost::copy_exception(current_exception_std_exception_wrapper<T>(e1,*e2));
216 return boost::copy_exception(current_exception_std_exception_wrapper<T>(e1));
221 current_exception_unknown_exception()
223 return boost::copy_exception(unknown_exception());
228 current_exception_unknown_boost_exception( boost::exception const & e )
230 return boost::copy_exception(unknown_exception(e));
235 current_exception_unknown_std_exception( std::exception const & e )
237 if( boost::exception const * be = get_boost_exception(&e) )
238 return current_exception_unknown_boost_exception(*be);
240 return boost::copy_exception(unknown_exception(e));
245 current_exception_impl()
252 exception_detail::clone_base & e )
254 return exception_ptr(e.clone());
257 std::domain_error & e )
259 return exception_detail::current_exception_std_exception(e);
262 std::invalid_argument & e )
264 return exception_detail::current_exception_std_exception(e);
267 std::length_error & e )
269 return exception_detail::current_exception_std_exception(e);
272 std::out_of_range & e )
274 return exception_detail::current_exception_std_exception(e);
277 std::logic_error & e )
279 return exception_detail::current_exception_std_exception(e);
282 std::range_error & e )
284 return exception_detail::current_exception_std_exception(e);
287 std::overflow_error & e )
289 return exception_detail::current_exception_std_exception(e);
292 std::underflow_error & e )
294 return exception_detail::current_exception_std_exception(e);
297 std::ios_base::failure & e )
299 return exception_detail::current_exception_std_exception(e);
302 std::runtime_error & e )
304 return exception_detail::current_exception_std_exception(e);
309 return exception_detail::current_exception_std_exception(e);
311 #ifndef BOOST_NO_TYPEID
315 return exception_detail::current_exception_std_exception(e);
318 std::bad_typeid & e )
320 return exception_detail::current_exception_std_exception(e);
324 std::bad_exception & e )
326 return exception_detail::current_exception_std_exception(e);
331 return exception_detail::current_exception_unknown_std_exception(e);
334 boost::exception & e )
336 return exception_detail::current_exception_unknown_boost_exception(e);
341 return exception_detail::current_exception_unknown_exception();
354 ret=exception_detail::current_exception_impl();
359 ret=exception_detail::exception_ptr_bad_alloc<42>::e;
366 ret=exception_detail::current_exception_std_exception(std::bad_exception());
371 ret=exception_detail::exception_ptr_bad_alloc<42>::e;
385 rethrow_exception( exception_ptr const & p )
393 diagnostic_information( exception_ptr const & p )
398 rethrow_exception(p);
403 return current_exception_diagnostic_information();
410 to_string( exception_ptr const & p )
412 std::string s='\n'+diagnostic_information(p);
413 std::string padding(" ");
416 for( std::string::const_iterator i=s.begin(),e=s.end(); i!=e; ++i )
428 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)