diff --git a/doc/throw_exception.html b/doc/throw_exception.html new file mode 100644 index 0000000..853c8aa --- /dev/null +++ b/doc/throw_exception.html @@ -0,0 +1,67 @@ + + + + + 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
+    }
+

Requirements:

+

E must derive publicly from std::exception.

+

Effects:

+
  • If BOOST_NO_EXCEPTIONS is not defined, boost::throw_exception(e) is equivalent to throw boost::enable_current_exception(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..c8a7e72 --- /dev/null +++ b/include/boost/exception/exception.hpp @@ -0,0 +1,127 @@ +//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 +#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 * diagnostic_information( char const *, 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 + char const * + what() const throw() + { + return diagnostic_information(); + } + + virtual + char const * + diagnostic_information() const throw() + { + return _diagnostic_information(0); + } + + protected: + + exception() + { + } + + exception( exception const & e ): + data_(e.data_) + { + } + + char const * + _diagnostic_information( char const * std_what ) const throw() + { + if( data_ ) + try + { + char const * w = data_->diagnostic_information(std_what,typeid(*this)); + BOOST_ASSERT(0!=w); + return w; + } + catch(...) + { + } + return std_what ? std_what : typeid(*this).name(); + } + +#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) + //Force class exception to be abstract. + //Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected. + virtual ~exception() throw()=0; +#else +#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) ) + virtual //Disable bogus GCC warning. +#endif + ~exception() throw() + { + } +#endif + + 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_; + }; + +#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) //See above. + inline + exception:: + ~exception() throw() + { + } +#endif + } + +#endif diff --git a/include/boost/throw_exception.hpp b/include/boost/throw_exception.hpp index bb79a37..6555763 100644 --- a/include/boost/throw_exception.hpp +++ b/include/boost/throw_exception.hpp @@ -11,18 +11,30 @@ // boost/throw_exception.hpp // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 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) +// 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) // // http://www.boost.org/libs/utility/throw_exception.html // #include +#include +#include -#ifdef BOOST_NO_EXCEPTIONS -# include +#if !defined( BOOST_EXCEPTION_DISABLE ) && defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, < 0x590 ) +# define BOOST_EXCEPTION_DISABLE +#endif + +#if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1310 ) +# define BOOST_EXCEPTION_DISABLE +#endif + +#if !defined( BOOST_NO_EXCEPTIONS ) && !defined( BOOST_EXCEPTION_DISABLE ) +# include +# include #endif namespace boost @@ -30,13 +42,23 @@ namespace boost #ifdef BOOST_NO_EXCEPTIONS -void throw_exception(std::exception const & e); // user defined +void throw_exception( std::exception const & e ); // user defined #else -template inline void throw_exception(E const & e) +inline void throw_exception_assert_compatibility( std::exception const & ) { } + +template inline void throw_exception( E const & e ) { + //All boost exceptions are required to derive std::exception, + //to ensure compatibility with BOOST_NO_EXCEPTIONS. + throw_exception_assert_compatibility(e); + +#ifndef BOOST_EXCEPTION_DISABLE + throw enable_current_exception(enable_error_info(e)); +#else throw e; +#endif } #endif diff --git a/test/throw_exception_fail.cpp b/test/throw_exception_fail.cpp new file mode 100644 index 0000000..19fda91 --- /dev/null +++ b/test/throw_exception_fail.cpp @@ -0,0 +1,18 @@ +//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) + +#include + +struct +my_exception + { + }; + +void +tester() + { + //Must not compile, throw_exception requires exception types to derive std::exception. + boost::throw_exception(my_exception()); + }