//By Peter Dimov, example code from propsal N2179 #include "exception_ptr.hpp" #include #include #include //for ios_base::failure declaration #include "future.hpp" #include //.. include all the boost exceptions namespace boost { namespace detail { class _exp_throwable { protected: ~_exp_throwable() {} public: virtual void rethrow() = 0; }; template< class E > class _exp_throwable_impl: public _exp_throwable { private: E e_; public: _exp_throwable_impl() { } template< class A > _exp_throwable_impl( A const & a ): e_( a ) { } void rethrow() { throw e_; } }; #define BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( E ) catch( E const & e ) { return exception_ptr( new _exp_throwable_impl< E >( e ) ); } static exception_ptr _exp_current_exception() { try { throw; } // include the user exceptions #ifdef BOOST_EXCEPTION_PTR_CATCH_AND_RETURN_USER_EXCEPTIONS__HPP #include BOOST_EXCEPTION_PTR_CATCH_AND_RETURN_USER_EXCEPTIONS__HPP #endif // runtime_error standard subclasses BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::overflow_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::range_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::underflow_error) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::runtime_error ) // logic_error standard subclasses BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::domain_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::invalid_argument ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::length_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::out_of_range ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::logic_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::bad_alloc ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::bad_cast ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::bad_typeid ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::bad_exception ) // iostreams library BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( std::ios_base::failure ) // add more BOOST_EXCEPTION_PTR_CATCH_AND_RETURN for the C++ primitive types // boost.thread exceptions BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::lock_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::thread_resource_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::unsupported_thread_option ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::thread_permission_error ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::invalid_thread_argument ) BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::thread_exception ) #if BOOST_VERSION >= 105000 BOOST_EXCEPTION_PTR_CATCH_AND_RETURN( boost::thread_interrupted ) // boost 1.5 #endif // add more BOOST_EXCEPTION_PTR_CATCH_AND_RETURN for all the boost exceptions catch( std::exception const & e ) { return exception_ptr( new _exp_throwable_impl( e.what() ) ); } catch( ... ) { return exception_ptr( new _exp_throwable_impl() ); } } static exception_ptr s_bad_alloc( new _exp_throwable_impl< std::bad_alloc > ); exception_ptr current_exception() { try { return _exp_current_exception(); } catch( std::bad_alloc const & ) { return s_bad_alloc; } } void rethrow_exception( exception_ptr p ) { p->rethrow(); } } //detail } //namespace boost