From db3574bc9d69e6bd02084ac48c96519a2c67d27f Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 4 Mar 2008 01:41:17 +0000 Subject: [PATCH] boost exception [SVN r43485] --- doc/throw_exception.html | 54 ++++++++++++++++ include/boost/exception/exception.hpp | 90 +++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 doc/throw_exception.html create mode 100644 include/boost/exception/exception.hpp diff --git a/doc/throw_exception.html b/doc/throw_exception.html new file mode 100644 index 0000000..1a33afd --- /dev/null +++ b/doc/throw_exception.html @@ -0,0 +1,54 @@ + + + + + throw_exception + + + +
+
+
+
+ +

Boost Exception

+
+

throw_exception()

+

#include <boost/throw_exception.hpp>

+
namespace
+boost
+    {
+#ifdef BOOST_NO_EXCEPTIONS
+    void throw_exception( std::exception const & e ); // user defined
+#else
+    template <class E>
+    void throw_exception( E const & e );
+#endif
+    }
+

Effects:

+
  • If BOOST_NO_EXCEPTIONS is not defined, boost::throw_exception(e) is equivalent to throw boost::enable_exception_cloning(boost::enable_error_info(e)), unless BOOST_EXCEPTION_DISABLE is defined, in which case boost::throw_exception(e) is equivalent to throw e;
  • +
  • If BOOST_NO_EXCEPTIONS is defined, the function is left undefined, and the user is expected to supply an appropriate definition. Callers of throw_exception are allowed to assume that the function never returns; therefore, if the user-defined throw_exception returns, the behavior is undefined.
  • +
+

See also:

+ + +
+
+
+ + diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp new file mode 100644 index 0000000..ec1bf1b --- /dev/null +++ b/include/boost/exception/exception.hpp @@ -0,0 +1,90 @@ +//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_274DA366004E11DCB1DDFE2E56D89593 +#define UUID_274DA366004E11DCB1DDFE2E56D89593 + +#include +#include +#include + +namespace +boost + { + template + class shared_ptr; + + namespace + exception_detail + { + class error_info_base; + + struct + error_info_container: + public exception_detail::counted_base + { + virtual char const * what( std::type_info const & ) const = 0; + virtual shared_ptr get( std::type_info const & ) const = 0; + virtual void set( shared_ptr const & ) = 0; + }; + } + + template + class error_info; + + template + E const & operator<<( E const &, error_info const & ); + + template + shared_ptr get_error_info( E const & ); + + class + exception + { + public: + + virtual ~exception() throw()=0; + virtual char const * what() const throw(); + + private: + + shared_ptr get( std::type_info const & ) const; + void set( shared_ptr const & ) const; + + template + friend E const & operator<<( E const &, error_info const & ); + + template + friend shared_ptr get_error_info( E const & ); + + intrusive_ptr mutable data_; + }; + + inline + exception:: + ~exception() throw() + { + } + + inline + char const * + exception:: + what() const throw() + { + if( data_ ) + try + { + char const * w = data_->what(typeid(*this)); + BOOST_ASSERT(0!=w); + return w; + } + catch(...) + { + } + return typeid(*this).name(); + } + } + +#endif