throw_exception
+
#include <boost/throw_exception.hpp>
namespace
boost
{
-#ifdef BOOST_NO_EXCEPTIONS
+ #ifdef BOOST_NO_EXCEPTIONS
+
void throw_exception( std::exception const & e ); // user defined
-#else
+
+ #else
+
template <class E>
void throw_exception( E const & e );
-#endif
+
+ #endif
}
Requirements:
-
E must derive publicly from std::exception.
+
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.
+- 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
index 4129833..c8a7e72 100644
--- a/include/boost/exception/exception.hpp
+++ b/include/boost/exception/exception.hpp
@@ -27,7 +27,7 @@ boost
error_info_container:
public exception_detail::counted_base
{
- virtual char const * what( std::type_info const & ) const = 0;
+ 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;
};
@@ -51,17 +51,14 @@ boost
char const *
what() const throw()
{
- if( data_ )
- try
- {
- char const * w = data_->what(typeid(*this));
- BOOST_ASSERT(0!=w);
- return w;
- }
- catch(...)
- {
- }
- return typeid(*this).name();
+ return diagnostic_information();
+ }
+
+ virtual
+ char const *
+ diagnostic_information() const throw()
+ {
+ return _diagnostic_information(0);
}
protected:
@@ -75,6 +72,22 @@ boost
{
}
+ 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.