2008-03-04 01:41:17 +00:00
|
|
|
//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
|
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
#include <boost/exception/detail/type_info.hpp>
|
2008-05-03 19:51:41 +00:00
|
|
|
#include <boost/detail/workaround.hpp>
|
2008-03-04 01:41:17 +00:00
|
|
|
#include <boost/exception/detail/counted_base.hpp>
|
|
|
|
#include <boost/intrusive_ptr.hpp>
|
|
|
|
#include <typeinfo>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
boost
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
class exception;
|
|
|
|
|
2008-04-08 21:29:37 +00:00
|
|
|
template <class T>
|
|
|
|
class shared_ptr;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
exception_detail
|
|
|
|
{
|
|
|
|
class error_info_base;
|
|
|
|
|
|
|
|
struct
|
|
|
|
error_info_container:
|
|
|
|
public exception_detail::counted_base
|
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
virtual char const * diagnostic_information( char const *, char const * ) const = 0;
|
|
|
|
virtual shared_ptr<error_info_base const> get( type_info_ const & ) const = 0;
|
|
|
|
virtual void set( shared_ptr<error_info_base const> const &, type_info_ const & ) = 0;
|
2008-04-08 21:29:37 +00:00
|
|
|
};
|
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
template <class ErrorInfo>
|
|
|
|
shared_ptr<typename ErrorInfo::value_type const> get_data( exception const & );
|
2008-04-08 21:29:37 +00:00
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
void set_data( exception const *, shared_ptr<exception_detail::error_info_base const> const &, exception_detail::type_info_ const & );
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
|
|
|
|
class
|
|
|
|
exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-06-25 23:27:56 +00:00
|
|
|
virtual
|
|
|
|
char const *
|
|
|
|
diagnostic_information() const throw()
|
|
|
|
{
|
|
|
|
return _diagnostic_information(0);
|
2008-05-11 02:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
exception()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
exception( exception const & e ):
|
|
|
|
data_(e.data_)
|
|
|
|
{
|
|
|
|
}
|
2008-05-03 19:51:41 +00:00
|
|
|
|
2008-06-25 23:27:56 +00:00
|
|
|
char const *
|
|
|
|
_diagnostic_information( char const * std_what ) const throw()
|
|
|
|
{
|
|
|
|
if( data_ )
|
|
|
|
try
|
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
char const * w = data_->diagnostic_information(std_what,dynamic_type_name());
|
|
|
|
BOOST_ASSERT(w!=0);
|
2008-06-25 23:27:56 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
}
|
2008-08-28 23:49:55 +00:00
|
|
|
return std_what ? std_what : dynamic_type_name();
|
2008-06-25 23:27:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-03 19:51:41 +00:00
|
|
|
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
|
2008-05-11 02:15:49 +00:00
|
|
|
//Force class exception to be abstract.
|
|
|
|
//Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected.
|
|
|
|
virtual ~exception() throw()=0;
|
2008-05-03 19:51:41 +00:00
|
|
|
#else
|
|
|
|
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
2008-05-11 02:15:49 +00:00
|
|
|
virtual //Disable bogus GCC warning.
|
2008-05-03 19:51:41 +00:00
|
|
|
#endif
|
2008-05-11 02:15:49 +00:00
|
|
|
~exception() throw()
|
|
|
|
{
|
|
|
|
}
|
2008-05-03 19:51:41 +00:00
|
|
|
#endif
|
2008-04-08 21:29:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
friend void exception_detail::set_data( exception const *, shared_ptr<exception_detail::error_info_base const> const &, exception_detail::type_info_ const & );
|
2008-04-08 21:29:37 +00:00
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
template <class ErrorInfo>
|
|
|
|
friend shared_ptr<typename ErrorInfo::value_type const> exception_detail::get_data( exception const & );
|
2008-04-08 21:29:37 +00:00
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
char const *
|
|
|
|
dynamic_type_name() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
#if defined(BOOST_NO_RTTI) || defined(BOOST_NO_TYPEID)
|
|
|
|
"Unknown type deriving from boost::exception"
|
|
|
|
#else
|
|
|
|
typeid(*this).name()
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
|
2008-08-20 21:48:35 +00:00
|
|
|
mutable intrusive_ptr<exception_detail::error_info_container> data_;
|
2008-04-08 21:29:37 +00:00
|
|
|
};
|
|
|
|
|
2008-05-03 19:51:41 +00:00
|
|
|
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) //See above.
|
2008-05-11 02:15:49 +00:00
|
|
|
inline
|
|
|
|
exception::
|
|
|
|
~exception() throw()
|
|
|
|
{
|
|
|
|
}
|
2008-05-03 19:51:41 +00:00
|
|
|
#endif
|
2008-05-11 02:15:49 +00:00
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
#endif
|