forked from boostorg/exception
Further simplified enable_current_exception. Improved exception_ptr testing.
[SVN r48455]
This commit is contained in:
@ -1,48 +0,0 @@
|
|||||||
//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_F7D5662CCB0F11DCA353CAC656D89593
|
|
||||||
#define UUID_F7D5662CCB0F11DCA353CAC656D89593
|
|
||||||
|
|
||||||
#include <boost/detail/workaround.hpp>
|
|
||||||
|
|
||||||
namespace
|
|
||||||
boost
|
|
||||||
{
|
|
||||||
namespace
|
|
||||||
exception_detail
|
|
||||||
{
|
|
||||||
class clone_base;
|
|
||||||
|
|
||||||
struct
|
|
||||||
new_clone
|
|
||||||
{
|
|
||||||
clone_base const * c_;
|
|
||||||
void (*d_)(clone_base const *);
|
|
||||||
};
|
|
||||||
|
|
||||||
class
|
|
||||||
cloning_base
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual new_clone clone() const = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
|
||||||
virtual //Disable bogus GCC warning.
|
|
||||||
#endif
|
|
||||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
|
|
||||||
virtual //Disable bogus msvc warning.
|
|
||||||
#endif
|
|
||||||
~cloning_base() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -7,9 +7,6 @@
|
|||||||
#define UUID_78CC85B2914F11DC8F47B48E55D89593
|
#define UUID_78CC85B2914F11DC8F47B48E55D89593
|
||||||
|
|
||||||
#include <boost/exception/exception.hpp>
|
#include <boost/exception/exception.hpp>
|
||||||
#include <boost/exception/detail/cloning_base.hpp>
|
|
||||||
#include <boost/assert.hpp>
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
boost
|
boost
|
||||||
@ -17,6 +14,22 @@ boost
|
|||||||
namespace
|
namespace
|
||||||
exception_detail
|
exception_detail
|
||||||
{
|
{
|
||||||
|
class
|
||||||
|
clone_base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual clone_base const * clone() const = 0;
|
||||||
|
virtual void rethrow() const = 0;
|
||||||
|
virtual ~clone_base() throw() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
clone_base::
|
||||||
|
~clone_base() throw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
copy_boost_exception( exception * a, exception const * b )
|
copy_boost_exception( exception * a, exception const * b )
|
||||||
@ -30,14 +43,11 @@ boost
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
|
||||||
new_clone make_clone( T const & );
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class
|
class
|
||||||
clone_impl:
|
clone_impl:
|
||||||
public T,
|
public T,
|
||||||
public cloning_base
|
public clone_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -54,107 +64,18 @@ boost
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
new_clone
|
clone_base const *
|
||||||
clone() const
|
clone() const
|
||||||
{
|
{
|
||||||
return make_clone<T>(*this);
|
return new clone_impl(*this);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
class
|
|
||||||
clone_base
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void rethrow() const=0;
|
|
||||||
virtual ~clone_base() throw()=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline
|
|
||||||
clone_base::
|
|
||||||
~clone_base() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
struct
|
|
||||||
bad_alloc_impl:
|
|
||||||
public clone_base,
|
|
||||||
public std::bad_alloc
|
|
||||||
{
|
|
||||||
void
|
void
|
||||||
rethrow() const
|
rethrow() const
|
||||||
{
|
{
|
||||||
throw *this;
|
throw *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class
|
|
||||||
exception_clone:
|
|
||||||
public T,
|
|
||||||
public clone_base
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
explicit
|
|
||||||
exception_clone( T const & x ):
|
|
||||||
T(x)
|
|
||||||
{
|
|
||||||
copy_boost_exception(this,&x);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
~exception_clone() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rethrow() const
|
|
||||||
{
|
|
||||||
throw clone_impl<T>(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
delete_clone( clone_base const * c )
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(c!=0);
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
delete_clone_noop( clone_base const * )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
new_clone
|
|
||||||
make_clone( T const & x )
|
|
||||||
{
|
|
||||||
new_clone tmp = {0,0};
|
|
||||||
try
|
|
||||||
{
|
|
||||||
tmp.c_=new exception_clone<T>(x);
|
|
||||||
tmp.d_=&delete_clone;
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::bad_alloc & )
|
|
||||||
{
|
|
||||||
static bad_alloc_impl bad_alloc;
|
|
||||||
tmp.c_=&bad_alloc;
|
|
||||||
tmp.d_=&delete_clone_noop;
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
... )
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(0);
|
|
||||||
}
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
#ifndef UUID_FA5836A2CADA11DC8CD47C8555D89593
|
#ifndef UUID_FA5836A2CADA11DC8CD47C8555D89593
|
||||||
#define UUID_FA5836A2CADA11DC8CD47C8555D89593
|
#define UUID_FA5836A2CADA11DC8CD47C8555D89593
|
||||||
|
|
||||||
#include <boost/exception/enable_current_exception.hpp>
|
|
||||||
#include <boost/exception/detail/get_boost_exception.hpp>
|
#include <boost/exception/detail/get_boost_exception.hpp>
|
||||||
|
#include <boost/exception/enable_current_exception.hpp>
|
||||||
#include <boost/detail/atomic_count.hpp>
|
#include <boost/detail/atomic_count.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <new>
|
#include <new>
|
||||||
@ -31,19 +31,19 @@ boost
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
set( new_clone const & nc )
|
set( clone_base const * c )
|
||||||
{
|
{
|
||||||
clone_ = nc.c_;
|
clone_ = c;
|
||||||
clone_deleter_ = nc.d_;
|
|
||||||
BOOST_ASSERT(clone_!=0);
|
BOOST_ASSERT(clone_!=0);
|
||||||
BOOST_ASSERT(clone_deleter_!=0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rethrow() const
|
rethrow() const
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(clone_!=0);
|
if( clone_ )
|
||||||
clone_->rethrow();
|
clone_->rethrow();
|
||||||
|
else
|
||||||
|
throw enable_current_exception(std::bad_alloc());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -58,7 +58,7 @@ boost
|
|||||||
~counted_clone() throw()
|
~counted_clone() throw()
|
||||||
{
|
{
|
||||||
if( clone_ )
|
if( clone_ )
|
||||||
clone_deleter_(clone_);
|
delete clone_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -74,14 +74,114 @@ boost
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct
|
||||||
|
bad_alloc_tag
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
struct
|
||||||
|
bad_exception_tag
|
||||||
|
{
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef intrusive_ptr<exception_detail::counted_clone const> exception_ptr;
|
class exception_ptr;
|
||||||
|
void rethrow_exception( exception_ptr const & );
|
||||||
|
|
||||||
|
class
|
||||||
|
exception_ptr
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
friend void rethrow_exception( exception_ptr const & );
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
bad_alloc_caught,
|
||||||
|
clone_failed,
|
||||||
|
ok
|
||||||
|
} what_happened_;
|
||||||
|
|
||||||
|
intrusive_ptr<exception_detail::counted_clone> c_;
|
||||||
|
|
||||||
|
void
|
||||||
|
rethrow() const
|
||||||
|
{
|
||||||
|
switch(
|
||||||
|
what_happened_ )
|
||||||
|
{
|
||||||
|
case
|
||||||
|
bad_alloc_caught:
|
||||||
|
throw enable_current_exception(std::bad_alloc());
|
||||||
|
case
|
||||||
|
clone_failed:
|
||||||
|
throw enable_current_exception(std::bad_exception());
|
||||||
|
case
|
||||||
|
ok:
|
||||||
|
BOOST_ASSERT(c_.get()!=0);
|
||||||
|
c_->rethrow();
|
||||||
|
}
|
||||||
|
BOOST_ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef intrusive_ptr<exception_detail::counted_clone> exception_ptr::*unspecified_bool_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit
|
||||||
|
exception_ptr( exception_detail::bad_alloc_tag ):
|
||||||
|
what_happened_(bad_alloc_caught)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
exception_ptr( exception_detail::bad_exception_tag ):
|
||||||
|
what_happened_(clone_failed)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
exception_ptr():
|
||||||
|
what_happened_(ok)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
exception_ptr( intrusive_ptr<exception_detail::counted_clone> const & c ):
|
||||||
|
what_happened_(ok),
|
||||||
|
c_(c)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(c_.get()!=0);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend
|
||||||
|
bool
|
||||||
|
operator==( exception_ptr const & a, exception_ptr const & b )
|
||||||
|
{
|
||||||
|
return
|
||||||
|
a.what_happened_==ok &&
|
||||||
|
b.what_happened_==ok &&
|
||||||
|
a.c_==b.c_;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend
|
||||||
|
bool
|
||||||
|
operator!=( exception_ptr const & a, exception_ptr const & b )
|
||||||
|
{
|
||||||
|
return !(a==b);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator unspecified_bool_type() const
|
||||||
|
{
|
||||||
|
return (what_happened_!=ok || c_) ? &exception_ptr::c_ : 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class
|
class
|
||||||
unknown_exception:
|
unknown_exception:
|
||||||
public exception,
|
public exception,
|
||||||
public std::exception
|
public std::exception,
|
||||||
|
public exception_detail::clone_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -98,6 +198,20 @@ boost
|
|||||||
~unknown_exception() throw()
|
~unknown_exception() throw()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
clone_base const *
|
||||||
|
clone() const
|
||||||
|
{
|
||||||
|
return new unknown_exception(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rethrow() const
|
||||||
|
{
|
||||||
|
throw *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -107,7 +221,8 @@ boost
|
|||||||
class
|
class
|
||||||
current_exception_std_exception_wrapper:
|
current_exception_std_exception_wrapper:
|
||||||
public T,
|
public T,
|
||||||
public boost::exception
|
public boost::exception,
|
||||||
|
public clone_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -126,6 +241,20 @@ boost
|
|||||||
~current_exception_std_exception_wrapper() throw()
|
~current_exception_std_exception_wrapper() throw()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
clone_base const *
|
||||||
|
clone() const
|
||||||
|
{
|
||||||
|
return new current_exception_std_exception_wrapper(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rethrow() const
|
||||||
|
{
|
||||||
|
throw *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -135,10 +264,10 @@ boost
|
|||||||
{
|
{
|
||||||
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
||||||
if( boost::exception const * e2 = get_boost_exception(&e1) )
|
if( boost::exception const * e2 = get_boost_exception(&e1) )
|
||||||
x->set(exception_detail::make_clone(current_exception_std_exception_wrapper<T>(e1,*e2)));
|
x->set(new current_exception_std_exception_wrapper<T>(e1,*e2));
|
||||||
else
|
else
|
||||||
x->set(exception_detail::make_clone(current_exception_std_exception_wrapper<T>(e1)));
|
x->set(new current_exception_std_exception_wrapper<T>(e1));
|
||||||
return x;
|
return exception_ptr(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -146,8 +275,8 @@ boost
|
|||||||
current_exception_unknown_exception()
|
current_exception_unknown_exception()
|
||||||
{
|
{
|
||||||
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
||||||
x->set(exception_detail::make_clone(unknown_exception()));
|
x->set(new unknown_exception());
|
||||||
return x;
|
return exception_ptr(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -157,8 +286,8 @@ boost
|
|||||||
if( boost::exception const * be = get_boost_exception(&e) )
|
if( boost::exception const * be = get_boost_exception(&e) )
|
||||||
{
|
{
|
||||||
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
||||||
x->set(exception_detail::make_clone(unknown_exception(*be)));
|
x->set(new unknown_exception(*be));
|
||||||
return x;
|
return exception_ptr(x);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return current_exception_unknown_exception();
|
return current_exception_unknown_exception();
|
||||||
@ -169,8 +298,8 @@ boost
|
|||||||
current_exception_unknown_boost_exception( boost::exception const & e )
|
current_exception_unknown_boost_exception( boost::exception const & e )
|
||||||
{
|
{
|
||||||
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
||||||
x->set(exception_detail::make_clone(unknown_exception(e)));
|
x->set(new unknown_exception(e));
|
||||||
return x;
|
return exception_ptr(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,64 +309,77 @@ boost
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
throw;
|
try
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
exception_detail::clone_base & e )
|
||||||
|
{
|
||||||
|
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
||||||
|
x->set(e.clone());
|
||||||
|
return exception_ptr(x);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::invalid_argument & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::out_of_range & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::logic_error & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::bad_alloc & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::bad_cast & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::bad_typeid & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::bad_exception & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
std::exception & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_unknown_std_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
boost::exception & e )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_unknown_boost_exception(e);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
return exception_detail::current_exception_unknown_exception();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
exception_detail::cloning_base & e )
|
std::bad_alloc & )
|
||||||
{
|
{
|
||||||
intrusive_ptr<exception_detail::counted_clone> x(new exception_detail::counted_clone);
|
return exception_ptr( exception_detail::bad_alloc_tag() );
|
||||||
x->set(e.clone());
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::invalid_argument & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::out_of_range & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::logic_error & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::bad_alloc & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::bad_cast & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::bad_typeid & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::bad_exception & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
std::exception & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_unknown_std_exception(e);
|
|
||||||
}
|
|
||||||
catch(
|
|
||||||
boost::exception & e )
|
|
||||||
{
|
|
||||||
return exception_detail::current_exception_unknown_boost_exception(e);
|
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
return exception_detail::current_exception_unknown_exception();
|
return exception_ptr( exception_detail::bad_exception_tag() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +402,7 @@ boost
|
|||||||
void
|
void
|
||||||
rethrow_exception( exception_ptr const & p )
|
rethrow_exception( exception_ptr const & p )
|
||||||
{
|
{
|
||||||
p->rethrow();
|
p.rethrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,25 @@
|
|||||||
|
|
||||||
typedef boost::error_info<struct my_tag,int> my_info;
|
typedef boost::error_info<struct my_tag,int> my_info;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct
|
||||||
|
may_throw_on_copy
|
||||||
|
{
|
||||||
|
may_throw_on_copy():
|
||||||
|
throw_(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
may_throw_on_copy( may_throw_on_copy const & x ):
|
||||||
|
throw_(x.throw_)
|
||||||
|
{
|
||||||
|
if( throw_ )
|
||||||
|
throw T();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool throw_;
|
||||||
|
};
|
||||||
|
|
||||||
struct
|
struct
|
||||||
derives_nothing
|
derives_nothing
|
||||||
{
|
{
|
||||||
@ -66,6 +85,9 @@ test_std_exception()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -74,6 +96,24 @@ test_std_exception()
|
|||||||
catch(
|
catch(
|
||||||
T & )
|
T & )
|
||||||
{
|
{
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
T & )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
@ -95,6 +135,9 @@ test_std_exception_what()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -104,6 +147,89 @@ test_std_exception_what()
|
|||||||
T & x )
|
T & x )
|
||||||
{
|
{
|
||||||
BOOST_TEST(std::string("what")==x.what());
|
BOOST_TEST(std::string("what")==x.what());
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
T & x )
|
||||||
|
{
|
||||||
|
BOOST_TEST(std::string("what")==x.what());
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Throw,class Catch>
|
||||||
|
void
|
||||||
|
test_throw_on_copy()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw boost::enable_current_exception(may_throw_on_copy<Throw>());
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
may_throw_on_copy<Throw> & x )
|
||||||
|
{
|
||||||
|
x.throw_=true;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
Catch & )
|
||||||
|
{
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
Catch & )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
@ -116,6 +242,10 @@ test_std_exception_what()
|
|||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
BOOST_TEST( boost::exception_ptr()==boost::exception_ptr() );
|
||||||
|
BOOST_TEST( !(boost::exception_ptr()!=boost::exception_ptr()) );
|
||||||
|
BOOST_TEST( !boost::exception_ptr() );
|
||||||
|
|
||||||
int count=0;
|
int count=0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -125,6 +255,9 @@ main()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -150,6 +283,9 @@ main()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -158,6 +294,24 @@ main()
|
|||||||
catch(
|
catch(
|
||||||
derives_std_exception & )
|
derives_std_exception & )
|
||||||
{
|
{
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
derives_std_exception & )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
@ -174,6 +328,9 @@ main()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -206,6 +363,9 @@ main()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -217,6 +377,27 @@ main()
|
|||||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||||
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||||
BOOST_TEST(*p==42);
|
BOOST_TEST(*p==42);
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
boost::unknown_exception & x )
|
||||||
|
{
|
||||||
|
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||||
|
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||||
|
BOOST_TEST(*p==42);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
@ -233,6 +414,9 @@ main()
|
|||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
boost::exception_ptr p = boost::current_exception();
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rethrow_exception(p);
|
rethrow_exception(p);
|
||||||
@ -244,6 +428,27 @@ main()
|
|||||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||||
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||||
BOOST_TEST(*p==42);
|
BOOST_TEST(*p==42);
|
||||||
|
boost::exception_ptr p = boost::current_exception();
|
||||||
|
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||||
|
BOOST_TEST(p!=boost::exception_ptr());
|
||||||
|
BOOST_TEST(p);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rethrow_exception(p);
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
boost::unknown_exception & x )
|
||||||
|
{
|
||||||
|
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||||
|
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||||
|
BOOST_TEST(*p==42);
|
||||||
|
}
|
||||||
|
catch(
|
||||||
|
... )
|
||||||
|
{
|
||||||
|
BOOST_TEST(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
@ -252,5 +457,8 @@ main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_throw_on_copy<std::bad_alloc,std::bad_alloc>();
|
||||||
|
test_throw_on_copy<int,std::bad_exception>();
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user