mirror of
https://github.com/boostorg/exception.git
synced 2025-07-20 16:02:06 +02:00
exception_ptr bad_alloc refactoring
[SVN r59431]
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,9 @@ boost
|
|||||||
{
|
{
|
||||||
typedef shared_ptr<exception_detail::clone_base const> exception_ptr;
|
typedef shared_ptr<exception_detail::clone_base const> exception_ptr;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
exception_ptr copy_exception( T const & );
|
||||||
|
|
||||||
#ifndef BOOST_NO_RTTI
|
#ifndef BOOST_NO_RTTI
|
||||||
typedef error_info<struct tag_original_exception_type,std::type_info const *> original_exception_type;
|
typedef error_info<struct tag_original_exception_type,std::type_info const *> original_exception_type;
|
||||||
|
|
||||||
@ -44,37 +47,42 @@ boost
|
|||||||
namespace
|
namespace
|
||||||
exception_detail
|
exception_detail
|
||||||
{
|
{
|
||||||
inline
|
struct
|
||||||
static
|
bad_alloc_:
|
||||||
exception_ptr
|
boost::exception,
|
||||||
exception_ptr_bad_alloc()
|
std::bad_alloc
|
||||||
{
|
|
||||||
static
|
|
||||||
struct
|
|
||||||
bad_alloc_:
|
|
||||||
std::bad_alloc,
|
|
||||||
exception_detail::clone_base
|
|
||||||
{
|
{
|
||||||
clone_base const *
|
};
|
||||||
clone() const
|
|
||||||
{
|
template <int Line>
|
||||||
return new bad_alloc_(*this);
|
exception_ptr
|
||||||
}
|
get_bad_alloc()
|
||||||
void
|
{
|
||||||
rethrow() const
|
static exception_ptr e = copy_exception(
|
||||||
{
|
bad_alloc_() <<
|
||||||
throw*this;
|
throw_function("boost::current_exception()") <<
|
||||||
}
|
throw_file(__FILE__) <<
|
||||||
} e;
|
throw_line(Line) );
|
||||||
return exception_ptr(exception_ptr(),&e);
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <int Line>
|
||||||
|
struct
|
||||||
|
exception_ptr_bad_alloc
|
||||||
|
{
|
||||||
|
static exception_ptr const e;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <int Line>
|
||||||
|
exception_ptr const
|
||||||
|
exception_ptr_bad_alloc<Line>::
|
||||||
|
e = get_bad_alloc<Line>();
|
||||||
}
|
}
|
||||||
|
|
||||||
class
|
class
|
||||||
unknown_exception:
|
unknown_exception:
|
||||||
public exception,
|
public boost::exception,
|
||||||
public std::exception,
|
public std::exception
|
||||||
public exception_detail::clone_base
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -101,18 +109,6 @@ boost
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
exception_detail::clone_base const *
|
|
||||||
clone() const
|
|
||||||
{
|
|
||||||
return new unknown_exception(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rethrow() const
|
|
||||||
{
|
|
||||||
throw*this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class E>
|
template <class E>
|
||||||
void
|
void
|
||||||
add_original_type( E const & e )
|
add_original_type( E const & e )
|
||||||
@ -130,8 +126,7 @@ 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:
|
||||||
|
|
||||||
@ -155,18 +150,6 @@ boost
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
clone_base const *
|
|
||||||
clone() const
|
|
||||||
{
|
|
||||||
return new current_exception_std_exception_wrapper(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rethrow() const
|
|
||||||
{
|
|
||||||
throw *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class E>
|
template <class E>
|
||||||
void
|
void
|
||||||
add_original_type( E const & e )
|
add_original_type( E const & e )
|
||||||
@ -179,7 +162,7 @@ boost
|
|||||||
|
|
||||||
#ifdef BOOST_NO_RTTI
|
#ifdef BOOST_NO_RTTI
|
||||||
template <class T>
|
template <class T>
|
||||||
exception const *
|
boost::exception const *
|
||||||
get_boost_exception( T const * )
|
get_boost_exception( T const * )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -187,7 +170,7 @@ boost
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
exception & x )
|
boost::exception & x )
|
||||||
{
|
{
|
||||||
return &x;
|
return &x;
|
||||||
}
|
}
|
||||||
@ -198,10 +181,10 @@ boost
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <class T>
|
template <class T>
|
||||||
exception const *
|
boost::exception const *
|
||||||
get_boost_exception( T const * x )
|
get_boost_exception( T const * x )
|
||||||
{
|
{
|
||||||
return dynamic_cast<exception const *>(x);
|
return dynamic_cast<boost::exception const *>(x);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -211,23 +194,23 @@ boost
|
|||||||
current_exception_std_exception( T const & e1 )
|
current_exception_std_exception( T const & e1 )
|
||||||
{
|
{
|
||||||
if( boost::exception const * e2 = get_boost_exception(&e1) )
|
if( boost::exception const * e2 = get_boost_exception(&e1) )
|
||||||
return shared_ptr<current_exception_std_exception_wrapper<T> const>(new current_exception_std_exception_wrapper<T>(e1,*e2));
|
return copy_exception(current_exception_std_exception_wrapper<T>(e1,*e2));
|
||||||
else
|
else
|
||||||
return shared_ptr<current_exception_std_exception_wrapper<T> const>(new current_exception_std_exception_wrapper<T>(e1));
|
return copy_exception(current_exception_std_exception_wrapper<T>(e1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
exception_ptr
|
exception_ptr
|
||||||
current_exception_unknown_exception()
|
current_exception_unknown_exception()
|
||||||
{
|
{
|
||||||
return shared_ptr<unknown_exception const>(new unknown_exception());
|
return copy_exception(unknown_exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
exception_ptr
|
exception_ptr
|
||||||
current_exception_unknown_boost_exception( boost::exception const & e )
|
current_exception_unknown_boost_exception( boost::exception const & e )
|
||||||
{
|
{
|
||||||
return shared_ptr<unknown_exception const>(new unknown_exception(e));
|
return copy_exception(unknown_exception(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -237,7 +220,7 @@ boost
|
|||||||
if( boost::exception const * be = get_boost_exception(&e) )
|
if( boost::exception const * be = get_boost_exception(&e) )
|
||||||
return current_exception_unknown_boost_exception(*be);
|
return current_exception_unknown_boost_exception(*be);
|
||||||
else
|
else
|
||||||
return shared_ptr<unknown_exception const>(new unknown_exception(e));
|
return copy_exception(unknown_exception(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -356,7 +339,7 @@ boost
|
|||||||
catch(
|
catch(
|
||||||
std::bad_alloc & )
|
std::bad_alloc & )
|
||||||
{
|
{
|
||||||
ret=exception_detail::exception_ptr_bad_alloc();
|
ret=exception_detail::exception_ptr_bad_alloc<__LINE__>::e;
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
@ -368,7 +351,7 @@ boost
|
|||||||
catch(
|
catch(
|
||||||
std::bad_alloc & )
|
std::bad_alloc & )
|
||||||
{
|
{
|
||||||
ret=exception_detail::exception_ptr_bad_alloc();
|
ret=exception_detail::exception_ptr_bad_alloc<__LINE__>::e;
|
||||||
}
|
}
|
||||||
catch(
|
catch(
|
||||||
... )
|
... )
|
||||||
|
@ -47,7 +47,7 @@ boost
|
|||||||
|
|
||||||
template <class Tag,class T>
|
template <class Tag,class T>
|
||||||
inline
|
inline
|
||||||
std::string
|
std::string
|
||||||
error_info<Tag,T>::
|
error_info<Tag,T>::
|
||||||
tag_typeid_name() const
|
tag_typeid_name() const
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user