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>
32 typedef error_info<struct tag_original_exception_type,std::type_info const *> original_exception_type;
36 to_string( original_exception_type const & x )
38 return x.value()->name();
43 exception_ptr current_exception();
44 void rethrow_exception( exception_ptr const & );
49 typedef bool exception_ptr::*unspecified_bool_type;
50 friend exception_ptr current_exception();
51 friend void rethrow_exception( exception_ptr const & );
53 shared_ptr<exception_detail::clone_base const> c_;
62 exception_ptr( bad_alloc_tag ):
68 exception_ptr( shared_ptr<exception_detail::clone_base const> const & c ):
80 throw enable_current_exception(std::bad_alloc());
88 return !bad_alloc_ && !c_;
98 ~exception_ptr() throw()
102 operator unspecified_bool_type() const
104 return empty() ? 0 : &exception_ptr::bad_alloc_;
109 operator==( exception_ptr const & a, exception_ptr const & b )
111 return a.c_==b.c_ && a.bad_alloc_==b.bad_alloc_;
116 operator!=( exception_ptr const & a, exception_ptr const & b )
125 public std::exception,
126 public exception_detail::clone_base
135 unknown_exception( std::exception const & e )
137 add_original_type(e);
141 unknown_exception( boost::exception const & e ):
144 add_original_type(e);
147 ~unknown_exception() throw()
153 exception_detail::clone_base const *
156 return new unknown_exception(*this);
167 add_original_type( E const & e )
169 #ifndef BOOST_NO_RTTI
170 (*this) << original_exception_type(&typeid(e));
180 current_exception_std_exception_wrapper:
182 public boost::exception,
188 current_exception_std_exception_wrapper( T const & e1 ):
191 add_original_type(e1);
194 current_exception_std_exception_wrapper( T const & e1, boost::exception const & e2 ):
198 add_original_type(e1);
201 ~current_exception_std_exception_wrapper() throw()
210 return new current_exception_std_exception_wrapper(*this);
221 add_original_type( E const & e )
223 #ifndef BOOST_NO_RTTI
224 (*this) << original_exception_type(&typeid(e));
232 get_boost_exception( T const * )
251 get_boost_exception( T const * x )
253 return dynamic_cast<exception const *>(x);
259 shared_ptr<clone_base const>
260 current_exception_std_exception( T const & e1 )
262 if( boost::exception const * e2 = get_boost_exception(&e1) )
263 return shared_ptr<current_exception_std_exception_wrapper<T> const>(new current_exception_std_exception_wrapper<T>(e1,*e2));
265 return shared_ptr<current_exception_std_exception_wrapper<T> const>(new current_exception_std_exception_wrapper<T>(e1));
269 shared_ptr<clone_base const>
270 current_exception_unknown_exception()
272 return shared_ptr<unknown_exception const>(new unknown_exception());
276 shared_ptr<clone_base const>
277 current_exception_unknown_boost_exception( boost::exception const & e )
279 return shared_ptr<unknown_exception const>(new unknown_exception(e));
283 shared_ptr<clone_base const>
284 current_exception_unknown_std_exception( std::exception const & e )
286 if( boost::exception const * be = get_boost_exception(&e) )
287 return current_exception_unknown_boost_exception(*be);
289 return shared_ptr<unknown_exception const>(new unknown_exception(e));
293 shared_ptr<clone_base const>
294 current_exception_impl()
301 exception_detail::clone_base & e )
303 return shared_ptr<exception_detail::clone_base const>(e.clone());
306 std::domain_error & e )
308 return exception_detail::current_exception_std_exception(e);
311 std::invalid_argument & e )
313 return exception_detail::current_exception_std_exception(e);
316 std::length_error & e )
318 return exception_detail::current_exception_std_exception(e);
321 std::out_of_range & e )
323 return exception_detail::current_exception_std_exception(e);
326 std::logic_error & e )
328 return exception_detail::current_exception_std_exception(e);
331 std::range_error & e )
333 return exception_detail::current_exception_std_exception(e);
336 std::overflow_error & e )
338 return exception_detail::current_exception_std_exception(e);
341 std::underflow_error & e )
343 return exception_detail::current_exception_std_exception(e);
346 std::ios_base::failure & e )
348 return exception_detail::current_exception_std_exception(e);
351 std::runtime_error & e )
353 return exception_detail::current_exception_std_exception(e);
358 return exception_detail::current_exception_std_exception(e);
360 #ifndef BOOST_NO_TYPEID
364 return exception_detail::current_exception_std_exception(e);
367 std::bad_typeid & e )
369 return exception_detail::current_exception_std_exception(e);
373 std::bad_exception & e )
375 return exception_detail::current_exception_std_exception(e);
380 return exception_detail::current_exception_unknown_std_exception(e);
383 boost::exception & e )
385 return exception_detail::current_exception_unknown_boost_exception(e);
390 return exception_detail::current_exception_unknown_exception();
401 return exception_ptr(exception_detail::current_exception_impl());
412 return exception_ptr(exception_detail::current_exception_std_exception(std::bad_exception()));
424 return exception_ptr(exception_ptr::bad_alloc_tag());
430 copy_exception( T const & e )
434 throw enable_current_exception(e);
439 return current_exception();
445 rethrow_exception( exception_ptr const & p )
452 diagnostic_information( exception_ptr const & p )
457 rethrow_exception(p);
462 return current_exception_diagnostic_information();
469 to_string( exception_ptr const & p )
471 std::string s='\n'+diagnostic_information(p);
472 std::string padding(" ");
475 for( std::string::const_iterator i=s.begin(),e=s.end(); i!=e; ++i )
487 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)