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/exception/detail/clone_current_exception.hpp>
24 #include <boost/shared_ptr.hpp>
34 BOOST_ATTRIBUTE_NORETURN void rethrow_exception( exception_ptr const & );
35 exception_ptr current_exception();
40 typedef boost::shared_ptr<exception_detail::clone_base const> impl;
42 friend void rethrow_exception( exception_ptr const & );
43 typedef exception_detail::clone_base const * (impl::*unspecified_bool_type)() const;
49 exception_ptr( impl const & ptr ):
54 operator==( exception_ptr const & other ) const
56 return ptr_==other.ptr_;
59 operator!=( exception_ptr const & other ) const
61 return ptr_!=other.ptr_;
63 operator unspecified_bool_type() const
65 return ptr_?&impl::get:0;
72 copy_exception( T const & e )
76 throw enable_current_exception(e);
81 return current_exception();
86 typedef error_info<struct tag_original_exception_type,std::type_info const *> original_exception_type;
90 to_string( original_exception_type const & x )
92 return x.value()->name();
104 ~bad_alloc_() throw() { }
112 ~bad_exception_() throw() { }
115 template <class Exception>
117 get_static_exception_object()
120 exception_detail::clone_impl<Exception> c(ba);
122 throw_function(BOOST_CURRENT_FUNCTION) <<
123 throw_file(__FILE__) <<
124 throw_line(__LINE__);
125 static exception_ptr ep(shared_ptr<exception_detail::clone_base const>(new exception_detail::clone_impl<Exception>(c)));
129 template <class Exception>
131 exception_ptr_static_exception_object
133 static exception_ptr const e;
136 template <class Exception>
138 exception_ptr_static_exception_object<Exception>::
139 e = get_static_exception_object<Exception>();
142 #if defined(__GNUC__)
143 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
144 # pragma GCC visibility push (default)
149 public boost::exception,
150 public std::exception
159 unknown_exception( std::exception const & e )
161 add_original_type(e);
165 unknown_exception( boost::exception const & e ):
168 add_original_type(e);
171 ~unknown_exception() throw()
179 add_original_type( E const & e )
181 #ifndef BOOST_NO_RTTI
182 (*this) << original_exception_type(&typeid(e));
186 #if defined(__GNUC__)
187 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
188 # pragma GCC visibility pop
197 current_exception_std_exception_wrapper:
199 public boost::exception
204 current_exception_std_exception_wrapper( T const & e1 ):
207 add_original_type(e1);
210 current_exception_std_exception_wrapper( T const & e1, boost::exception const & e2 ):
214 add_original_type(e1);
217 ~current_exception_std_exception_wrapper() throw()
225 add_original_type( E const & e )
227 #ifndef BOOST_NO_RTTI
228 (*this) << original_exception_type(&typeid(e));
235 boost::exception const *
236 get_boost_exception( T const * )
243 boost::exception & x )
254 boost::exception const *
255 get_boost_exception( T const * x )
257 return dynamic_cast<boost::exception const *>(x);
264 current_exception_std_exception( T const & e1 )
266 if( boost::exception const * e2 = get_boost_exception(&e1) )
267 return boost::copy_exception(current_exception_std_exception_wrapper<T>(e1,*e2));
269 return boost::copy_exception(current_exception_std_exception_wrapper<T>(e1));
274 current_exception_unknown_exception()
276 return boost::copy_exception(unknown_exception());
281 current_exception_unknown_boost_exception( boost::exception const & e )
283 return boost::copy_exception(unknown_exception(e));
288 current_exception_unknown_std_exception( std::exception const & e )
290 if( boost::exception const * be = get_boost_exception(&e) )
291 return current_exception_unknown_boost_exception(*be);
293 return boost::copy_exception(unknown_exception(e));
298 current_exception_impl()
300 exception_detail::clone_base const * e=0;
302 exception_detail::clone_current_exception(e) )
304 case exception_detail::clone_current_exception_result::
308 return exception_ptr(shared_ptr<exception_detail::clone_base const>(e));
310 case exception_detail::clone_current_exception_result::
314 return exception_detail::exception_ptr_static_exception_object<bad_alloc_>::e;
316 case exception_detail::clone_current_exception_result::
320 return exception_detail::exception_ptr_static_exception_object<bad_exception_>::e;
324 case exception_detail::clone_current_exception_result::
333 exception_detail::clone_base & e )
335 return exception_ptr(shared_ptr<exception_detail::clone_base const>(e.clone()));
338 std::domain_error & e )
340 return exception_detail::current_exception_std_exception(e);
343 std::invalid_argument & e )
345 return exception_detail::current_exception_std_exception(e);
348 std::length_error & e )
350 return exception_detail::current_exception_std_exception(e);
353 std::out_of_range & e )
355 return exception_detail::current_exception_std_exception(e);
358 std::logic_error & e )
360 return exception_detail::current_exception_std_exception(e);
363 std::range_error & e )
365 return exception_detail::current_exception_std_exception(e);
368 std::overflow_error & e )
370 return exception_detail::current_exception_std_exception(e);
373 std::underflow_error & e )
375 return exception_detail::current_exception_std_exception(e);
378 std::ios_base::failure & e )
380 return exception_detail::current_exception_std_exception(e);
383 std::runtime_error & e )
385 return exception_detail::current_exception_std_exception(e);
390 return exception_detail::current_exception_std_exception(e);
392 #ifndef BOOST_NO_TYPEID
396 return exception_detail::current_exception_std_exception(e);
399 std::bad_typeid & e )
401 return exception_detail::current_exception_std_exception(e);
405 std::bad_exception & e )
407 return exception_detail::current_exception_std_exception(e);
412 return exception_detail::current_exception_unknown_std_exception(e);
415 boost::exception & e )
417 return exception_detail::current_exception_unknown_boost_exception(e);
422 return exception_detail::current_exception_unknown_exception();
436 ret=exception_detail::current_exception_impl();
441 ret=exception_detail::exception_ptr_static_exception_object<exception_detail::bad_alloc_>::e;
446 ret=exception_detail::exception_ptr_static_exception_object<exception_detail::bad_exception_>::e;
452 BOOST_ATTRIBUTE_NORETURN
455 rethrow_exception( exception_ptr const & p )
465 diagnostic_information( exception_ptr const & p )
470 rethrow_exception(p);
475 return current_exception_diagnostic_information();
482 to_string( exception_ptr const & p )
484 std::string s='\n'+diagnostic_information(p);
485 std::string padding(" ");
488 for( std::string::const_iterator i=s.begin(),e=s.end(); i!=e; ++i )
500 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)