mirror of
https://github.com/boostorg/exception.git
synced 2025-06-30 14:31:03 +02:00
Compare commits
6 Commits
boost-1.46
...
boost-1.52
Author | SHA1 | Date | |
---|---|---|---|
3316f2e660 | |||
7e116a36b9 | |||
b3b930b7f5 | |||
a73deaa3f3 | |||
f5dc3715bc | |||
ef12c8b8fb |
14
build/Jamfile.v2
Normal file
14
build/Jamfile.v2
Normal file
@ -0,0 +1,14 @@
|
||||
# Boost Exception Library build Jamfile
|
||||
#
|
||||
# Copyright (c) 2006-2009 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)
|
||||
|
||||
project boost/exception
|
||||
: source-location ../src
|
||||
: requirements <link>static
|
||||
;
|
||||
|
||||
lib boost_exception : clone_current_exception_non_intrusive.cpp ;
|
||||
boost-install boost_exception ;
|
@ -9,7 +9,7 @@
|
||||
#if defined(_MSC_VER)
|
||||
#define BOOST_ATTRIBUTE_NORETURN __declspec(noreturn)
|
||||
#elif defined(__GNUC__)
|
||||
#define BOOST_ATTRIBUTE_NORETURN __attribute__((noreturn))
|
||||
#define BOOST_ATTRIBUTE_NORETURN __attribute__((__noreturn__))
|
||||
#else
|
||||
#define BOOST_ATTRIBUTE_NORETURN
|
||||
#endif
|
||||
|
47
include/boost/exception/detail/clone_current_exception.hpp
Normal file
47
include/boost/exception/detail/clone_current_exception.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
//Copyright (c) 2006-2009 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_81522C0EB56511DFAB613DB0DFD72085
|
||||
#define UUID_81522C0EB56511DFAB613DB0DFD72085
|
||||
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
# error This header requires exception handling to be enabled.
|
||||
#endif
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class clone_base;
|
||||
|
||||
#ifdef BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR
|
||||
int clone_current_exception_non_intrusive( clone_base const * & cloned );
|
||||
#endif
|
||||
|
||||
namespace
|
||||
clone_current_exception_result
|
||||
{
|
||||
int const success=0;
|
||||
int const bad_alloc=1;
|
||||
int const bad_exception=2;
|
||||
int const not_supported=3;
|
||||
}
|
||||
|
||||
inline
|
||||
int
|
||||
clone_current_exception( clone_base const * & cloned )
|
||||
{
|
||||
#ifdef BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR
|
||||
return clone_current_exception_non_intrusive(cloned);
|
||||
#else
|
||||
return clone_current_exception_result::not_supported;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -30,6 +30,7 @@ boost
|
||||
|
||||
protected:
|
||||
|
||||
virtual
|
||||
~error_info_base() throw()
|
||||
{
|
||||
}
|
||||
|
@ -20,18 +20,52 @@
|
||||
#include <boost/exception/info.hpp>
|
||||
#include <boost/exception/diagnostic_information.hpp>
|
||||
#include <boost/exception/detail/type_info.hpp>
|
||||
#include <boost/exception/detail/clone_current_exception.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <stdexcept>
|
||||
#include <new>
|
||||
#include <ios>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
typedef shared_ptr<exception_detail::clone_base const> exception_ptr;
|
||||
|
||||
class exception_ptr;
|
||||
BOOST_ATTRIBUTE_NORETURN void rethrow_exception( exception_ptr const & );
|
||||
exception_ptr current_exception();
|
||||
|
||||
class
|
||||
exception_ptr
|
||||
{
|
||||
typedef boost::shared_ptr<exception_detail::clone_base const> impl;
|
||||
impl ptr_;
|
||||
friend void rethrow_exception( exception_ptr const & );
|
||||
typedef exception_detail::clone_base const * (impl::*unspecified_bool_type)() const;
|
||||
public:
|
||||
exception_ptr()
|
||||
{
|
||||
}
|
||||
explicit
|
||||
exception_ptr( impl const & ptr ):
|
||||
ptr_(ptr)
|
||||
{
|
||||
}
|
||||
bool
|
||||
operator==( exception_ptr const & other ) const
|
||||
{
|
||||
return ptr_==other.ptr_;
|
||||
}
|
||||
bool
|
||||
operator!=( exception_ptr const & other ) const
|
||||
{
|
||||
return ptr_!=other.ptr_;
|
||||
}
|
||||
operator unspecified_bool_type() const
|
||||
{
|
||||
return ptr_?&impl::get:0;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
exception_ptr
|
||||
@ -67,35 +101,49 @@ boost
|
||||
boost::exception,
|
||||
std::bad_alloc
|
||||
{
|
||||
~bad_alloc_() throw() { }
|
||||
};
|
||||
|
||||
template <int Dummy>
|
||||
struct
|
||||
bad_exception_:
|
||||
boost::exception,
|
||||
std::bad_exception
|
||||
{
|
||||
~bad_exception_() throw() { }
|
||||
};
|
||||
|
||||
template <class Exception>
|
||||
exception_ptr
|
||||
get_bad_alloc()
|
||||
get_static_exception_object()
|
||||
{
|
||||
bad_alloc_ ba;
|
||||
exception_detail::clone_impl<bad_alloc_> c(ba);
|
||||
Exception ba;
|
||||
exception_detail::clone_impl<Exception> c(ba);
|
||||
c <<
|
||||
throw_function(BOOST_CURRENT_FUNCTION) <<
|
||||
throw_file(__FILE__) <<
|
||||
throw_line(__LINE__);
|
||||
static exception_ptr ep(new exception_detail::clone_impl<bad_alloc_>(c));
|
||||
static exception_ptr ep(shared_ptr<exception_detail::clone_base const>(new exception_detail::clone_impl<Exception>(c)));
|
||||
return ep;
|
||||
}
|
||||
|
||||
template <int Dummy>
|
||||
template <class Exception>
|
||||
struct
|
||||
exception_ptr_bad_alloc
|
||||
exception_ptr_static_exception_object
|
||||
{
|
||||
static exception_ptr const e;
|
||||
};
|
||||
|
||||
template <int Dummy>
|
||||
template <class Exception>
|
||||
exception_ptr const
|
||||
exception_ptr_bad_alloc<Dummy>::
|
||||
e = get_bad_alloc<Dummy>();
|
||||
exception_ptr_static_exception_object<Exception>::
|
||||
e = get_static_exception_object<Exception>();
|
||||
}
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility push (default)
|
||||
# endif
|
||||
#endif
|
||||
class
|
||||
unknown_exception:
|
||||
public boost::exception,
|
||||
@ -135,6 +183,11 @@ boost
|
||||
#endif
|
||||
}
|
||||
};
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
@ -244,101 +297,131 @@ boost
|
||||
exception_ptr
|
||||
current_exception_impl()
|
||||
{
|
||||
try
|
||||
exception_detail::clone_base const * e=0;
|
||||
switch(
|
||||
exception_detail::clone_current_exception(e) )
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
exception_detail::clone_base & e )
|
||||
{
|
||||
return exception_ptr(e.clone());
|
||||
}
|
||||
catch(
|
||||
std::domain_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::invalid_argument & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::length_error & 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::range_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::overflow_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::underflow_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::ios_base::failure & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::runtime_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::bad_alloc & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
case exception_detail::clone_current_exception_result::
|
||||
success:
|
||||
{
|
||||
BOOST_ASSERT(e!=0);
|
||||
return exception_ptr(shared_ptr<exception_detail::clone_base const>(e));
|
||||
}
|
||||
case exception_detail::clone_current_exception_result::
|
||||
bad_alloc:
|
||||
{
|
||||
BOOST_ASSERT(!e);
|
||||
return exception_detail::exception_ptr_static_exception_object<bad_alloc_>::e;
|
||||
}
|
||||
case exception_detail::clone_current_exception_result::
|
||||
bad_exception:
|
||||
{
|
||||
BOOST_ASSERT(!e);
|
||||
return exception_detail::exception_ptr_static_exception_object<bad_exception_>::e;
|
||||
}
|
||||
default:
|
||||
BOOST_ASSERT(0);
|
||||
case exception_detail::clone_current_exception_result::
|
||||
not_supported:
|
||||
{
|
||||
BOOST_ASSERT(!e);
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
exception_detail::clone_base & e )
|
||||
{
|
||||
return exception_ptr(shared_ptr<exception_detail::clone_base const>(e.clone()));
|
||||
}
|
||||
catch(
|
||||
std::domain_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::invalid_argument & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::length_error & 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::range_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::overflow_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::underflow_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::ios_base::failure & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::runtime_error & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::bad_alloc & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
#ifndef BOOST_NO_TYPEID
|
||||
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_cast & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
catch(
|
||||
std::bad_typeid & e )
|
||||
{
|
||||
return exception_detail::current_exception_std_exception(e);
|
||||
}
|
||||
#endif
|
||||
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(
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -348,7 +431,6 @@ boost
|
||||
current_exception()
|
||||
{
|
||||
exception_ptr ret;
|
||||
BOOST_ASSERT(!ret);
|
||||
try
|
||||
{
|
||||
ret=exception_detail::current_exception_impl();
|
||||
@ -356,36 +438,31 @@ boost
|
||||
catch(
|
||||
std::bad_alloc & )
|
||||
{
|
||||
ret=exception_detail::exception_ptr_bad_alloc<42>::e;
|
||||
ret=exception_detail::exception_ptr_static_exception_object<exception_detail::bad_alloc_>::e;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
try
|
||||
{
|
||||
ret=exception_detail::current_exception_std_exception(std::bad_exception());
|
||||
}
|
||||
catch(
|
||||
std::bad_alloc & )
|
||||
{
|
||||
ret=exception_detail::exception_ptr_bad_alloc<42>::e;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_ASSERT(0);
|
||||
}
|
||||
ret=exception_detail::exception_ptr_static_exception_object<exception_detail::bad_exception_>::e;
|
||||
}
|
||||
BOOST_ASSERT(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOST_ATTRIBUTE_NORETURN
|
||||
inline
|
||||
void
|
||||
rethrow_exception( exception_ptr const & p )
|
||||
{
|
||||
BOOST_ASSERT(p);
|
||||
p->rethrow();
|
||||
p.ptr_->rethrow();
|
||||
BOOST_ASSERT(0);
|
||||
#if defined(UNDER_CE)
|
||||
// some CE platforms don't define ::abort()
|
||||
exit(-1);
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline
|
||||
|
@ -53,11 +53,11 @@ boost
|
||||
struct
|
||||
type_info_
|
||||
{
|
||||
detail::sp_typeinfo const & type_;
|
||||
detail::sp_typeinfo const * type_;
|
||||
|
||||
explicit
|
||||
type_info_( detail::sp_typeinfo const & type ):
|
||||
type_(type)
|
||||
type_(&type)
|
||||
{
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ boost
|
||||
bool
|
||||
operator<( type_info_ const & a, type_info_ const & b )
|
||||
{
|
||||
return 0!=(a.type_.before(b.type_));
|
||||
return 0!=(a.type_->before(*b.type_));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <boost/exception/info.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#ifndef BOOST_NO_RTTI
|
||||
#include <boost/units/detail/utility.hpp>
|
||||
@ -85,19 +86,23 @@ boost
|
||||
char const *
|
||||
get_diagnostic_information( exception const & x, char const * header )
|
||||
{
|
||||
if( error_info_container * c=x.data_.get() )
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
#endif
|
||||
return c->diagnostic_information(header);
|
||||
error_info_container * c=x.data_.get();
|
||||
if( !c )
|
||||
x.data_.adopt(c=new exception_detail::error_info_container_impl);
|
||||
char const * di=c->diagnostic_information(header);
|
||||
BOOST_ASSERT(di!=0);
|
||||
return di;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline
|
||||
@ -122,22 +127,30 @@ boost
|
||||
std::ostringstream tmp;
|
||||
if( be )
|
||||
{
|
||||
if( char const * const * f=get_error_info<throw_file>(*be) )
|
||||
{
|
||||
tmp << *f;
|
||||
if( int const * l=get_error_info<throw_line>(*be) )
|
||||
tmp << '(' << *l << "): ";
|
||||
}
|
||||
tmp << "Throw in function ";
|
||||
if( char const * const * fn=get_error_info<throw_function>(*be) )
|
||||
tmp << *fn;
|
||||
char const * const * f=get_error_info<throw_file>(*be);
|
||||
int const * l=get_error_info<throw_line>(*be);
|
||||
char const * const * fn=get_error_info<throw_function>(*be);
|
||||
if( !f && !l && !fn )
|
||||
tmp << "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
|
||||
else
|
||||
tmp << "(unknown)";
|
||||
tmp << '\n';
|
||||
{
|
||||
if( f )
|
||||
{
|
||||
tmp << *f;
|
||||
if( int const * l=get_error_info<throw_line>(*be) )
|
||||
tmp << '(' << *l << "): ";
|
||||
}
|
||||
tmp << "Throw in function ";
|
||||
if( char const * const * fn=get_error_info<throw_function>(*be) )
|
||||
tmp << *fn;
|
||||
else
|
||||
tmp << "(unknown)";
|
||||
tmp << '\n';
|
||||
}
|
||||
}
|
||||
#ifndef BOOST_NO_RTTI
|
||||
tmp << std::string("Dynamic exception type: ") <<
|
||||
units::detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_.name()) << '\n';
|
||||
units::detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
|
||||
#endif
|
||||
if( with_what && se )
|
||||
tmp << "std::exception::what: " << wh << '\n';
|
||||
@ -166,7 +179,10 @@ boost
|
||||
{
|
||||
#endif
|
||||
(void) exception_detail::diagnostic_information_impl(&e,0,false);
|
||||
return exception_detail::get_diagnostic_information(e,0);
|
||||
if( char const * di=exception_detail::get_diagnostic_information(e,0) )
|
||||
return di;
|
||||
else
|
||||
return "Failed to produce boost::diagnostic_information_what()";
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(
|
||||
|
@ -9,10 +9,9 @@
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace exception_detail { class clone_base; };
|
||||
namespace exception_detail { class clone_base; }
|
||||
template <class Tag,class T> class error_info;
|
||||
template <class T> class shared_ptr;
|
||||
typedef shared_ptr<exception_detail::clone_base const> exception_ptr;
|
||||
class exception_ptr;
|
||||
typedef error_info<struct errinfo_nested_exception_,exception_ptr> errinfo_nested_exception;
|
||||
}
|
||||
|
||||
|
@ -3,4 +3,7 @@
|
||||
//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_EE7ECCA0433B11E1923E37064924019B
|
||||
#define UUID_EE7ECCA0433B11E1923E37064924019B
|
||||
namespace boost { template <class Tag,class T> class error_info; }
|
||||
#endif
|
||||
|
@ -132,7 +132,17 @@ boost
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility push (default)
|
||||
# endif
|
||||
#endif
|
||||
class exception;
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
class shared_ptr;
|
||||
@ -189,6 +199,11 @@ boost
|
||||
E const & set_info( E const &, throw_line const & );
|
||||
}
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility push (default)
|
||||
# endif
|
||||
#endif
|
||||
class
|
||||
exception
|
||||
{
|
||||
@ -250,6 +265,11 @@ boost
|
||||
mutable char const * throw_file_;
|
||||
mutable int throw_line_;
|
||||
};
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
inline
|
||||
exception::
|
||||
@ -290,6 +310,11 @@ boost
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility push (default)
|
||||
# endif
|
||||
#endif
|
||||
template <class T>
|
||||
struct
|
||||
error_info_injector:
|
||||
@ -306,6 +331,11 @@ boost
|
||||
{
|
||||
}
|
||||
};
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct large_size { char c[256]; };
|
||||
large_size dispatch_boost_exception( exception const * );
|
||||
@ -334,7 +364,7 @@ boost
|
||||
struct
|
||||
enable_error_info_return_type
|
||||
{
|
||||
typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception((T*)0))>::type type;
|
||||
typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
@ -353,6 +383,11 @@ boost
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility push (default)
|
||||
# endif
|
||||
#endif
|
||||
class
|
||||
clone_base
|
||||
{
|
||||
@ -366,6 +401,11 @@ boost
|
||||
{
|
||||
}
|
||||
};
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# pragma GCC visibility pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
inline
|
||||
void
|
||||
@ -390,8 +430,15 @@ boost
|
||||
class
|
||||
clone_impl:
|
||||
public T,
|
||||
public clone_base
|
||||
public virtual clone_base
|
||||
{
|
||||
struct clone_tag { };
|
||||
clone_impl( clone_impl const & x, clone_tag ):
|
||||
T(x)
|
||||
{
|
||||
copy_boost_exception(this,&x);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
@ -410,7 +457,7 @@ boost
|
||||
clone_base const *
|
||||
clone() const
|
||||
{
|
||||
return new clone_impl(*this);
|
||||
return new clone_impl(*this,clone_tag());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -97,7 +97,7 @@ boost
|
||||
{
|
||||
shared_ptr<error_info_base> const & p = i->second;
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==ti.type_ );
|
||||
BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
@ -109,7 +109,6 @@ boost
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
BOOST_ASSERT(*header!=0);
|
||||
std::ostringstream tmp;
|
||||
tmp << header;
|
||||
for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
|
||||
|
@ -18,6 +18,30 @@
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
template <
|
||||
class E >
|
||||
inline
|
||||
E const &
|
||||
operator<<(
|
||||
E const & x,
|
||||
tuple< > const & v )
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <
|
||||
class E,
|
||||
class Tag1,class T1 >
|
||||
inline
|
||||
E const &
|
||||
operator<<(
|
||||
E const & x,
|
||||
tuple<
|
||||
error_info<Tag1,T1> > const & v )
|
||||
{
|
||||
return x << v.template get<0>();
|
||||
}
|
||||
|
||||
template <
|
||||
class E,
|
||||
class Tag1,class T1,
|
||||
|
@ -1,5 +1,11 @@
|
||||
#ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
|
||||
#define BOOST_THROW_EXCEPTION_HPP_INCLUDED
|
||||
#ifndef UUID_AA15E74A856F11E08B8D93F24824019B
|
||||
#define UUID_AA15E74A856F11E08B8D93F24824019B
|
||||
#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
||||
#pragma warning(push,1)
|
||||
#endif
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
@ -79,7 +85,7 @@ template<class E> BOOST_ATTRIBUTE_NORETURN inline void throw_exception( E const
|
||||
set_info(
|
||||
set_info(
|
||||
set_info(
|
||||
boost::enable_error_info(x),
|
||||
enable_error_info(x),
|
||||
throw_function(current_function)),
|
||||
throw_file(file)),
|
||||
throw_line(line)));
|
||||
@ -88,4 +94,7 @@ template<class E> BOOST_ATTRIBUTE_NORETURN inline void throw_exception( E const
|
||||
#endif
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
|
||||
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
||||
|
320
src/clone_current_exception_non_intrusive.cpp
Normal file
320
src/clone_current_exception_non_intrusive.cpp
Normal file
@ -0,0 +1,320 @@
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
||||
//This MSVC-specific cpp file implements non-intrusive cloning of exception objects.
|
||||
//Based on an exception_ptr implementation by Anthony Williams.
|
||||
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
#error This file requires exception handling to be enabled.
|
||||
#endif
|
||||
|
||||
#include <boost/exception/detail/clone_current_exception.hpp>
|
||||
|
||||
#if defined(BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR) && defined(_MSC_VER) && defined(_M_IX86) && !defined(_M_X64)
|
||||
|
||||
//Non-intrusive cloning support implemented below, only for MSVC versions mentioned above.
|
||||
//Thanks Anthony Williams!
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#ifndef BOOST_NO_RTTI
|
||||
#include <typeinfo>
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <malloc.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
unsigned const exception_maximum_parameters=15;
|
||||
unsigned const exception_noncontinuable=1;
|
||||
|
||||
#if _MSC_VER==1310
|
||||
int const exception_info_offset=0x74;
|
||||
#elif (_MSC_VER==1400 || _MSC_VER==1500)
|
||||
int const exception_info_offset=0x80;
|
||||
#else
|
||||
int const exception_info_offset=-1;
|
||||
#endif
|
||||
|
||||
struct
|
||||
exception_record
|
||||
{
|
||||
unsigned long ExceptionCode;
|
||||
unsigned long ExceptionFlags;
|
||||
exception_record * ExceptionRecord;
|
||||
void * ExceptionAddress;
|
||||
unsigned long NumberParameters;
|
||||
ULONG_PTR ExceptionInformation[exception_maximum_parameters];
|
||||
};
|
||||
|
||||
struct
|
||||
exception_pointers
|
||||
{
|
||||
exception_record * ExceptionRecord;
|
||||
void * ContextRecord;
|
||||
};
|
||||
|
||||
unsigned const cpp_exception_code=0xE06D7363;
|
||||
unsigned const cpp_exception_magic_flag=0x19930520;
|
||||
unsigned const cpp_exception_parameter_count=3;
|
||||
|
||||
struct
|
||||
dummy_exception_type
|
||||
{
|
||||
};
|
||||
|
||||
typedef int(dummy_exception_type::*normal_copy_constructor_ptr)(void * src);
|
||||
typedef int(dummy_exception_type::*copy_constructor_with_virtual_base_ptr)(void * src,void * dst);
|
||||
typedef void (dummy_exception_type::*destructor_ptr)();
|
||||
|
||||
union
|
||||
cpp_copy_constructor
|
||||
{
|
||||
normal_copy_constructor_ptr normal_copy_constructor;
|
||||
copy_constructor_with_virtual_base_ptr copy_constructor_with_virtual_base;
|
||||
};
|
||||
|
||||
enum
|
||||
cpp_type_flags
|
||||
{
|
||||
class_is_simple_type=1,
|
||||
class_has_virtual_base=4
|
||||
};
|
||||
|
||||
struct
|
||||
cpp_type_info
|
||||
{
|
||||
unsigned flags;
|
||||
#ifndef BOOST_NO_RTTI
|
||||
void const * type_info;
|
||||
#else
|
||||
std::type_info * type_info;
|
||||
#endif
|
||||
int this_offset;
|
||||
int vbase_descr;
|
||||
int vbase_offset;
|
||||
unsigned long size;
|
||||
cpp_copy_constructor copy_constructor;
|
||||
};
|
||||
|
||||
struct
|
||||
cpp_type_info_table
|
||||
{
|
||||
unsigned count;
|
||||
const cpp_type_info * info[1];
|
||||
};
|
||||
|
||||
struct
|
||||
cpp_exception_type
|
||||
{
|
||||
unsigned flags;
|
||||
destructor_ptr destructor;
|
||||
void(*custom_handler)();
|
||||
cpp_type_info_table const * type_info_table;
|
||||
};
|
||||
|
||||
struct
|
||||
exception_object_deleter
|
||||
{
|
||||
cpp_exception_type const & et_;
|
||||
|
||||
exception_object_deleter( cpp_exception_type const & et ):
|
||||
et_(et)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
operator()( void * obj )
|
||||
{
|
||||
BOOST_ASSERT(obj!=0);
|
||||
dummy_exception_type * dummy_exception_ptr=reinterpret_cast<dummy_exception_type *>(obj);
|
||||
(dummy_exception_ptr->*(et_.destructor))();
|
||||
free(obj);
|
||||
}
|
||||
};
|
||||
|
||||
cpp_type_info const &
|
||||
get_cpp_type_info( cpp_exception_type const & et )
|
||||
{
|
||||
cpp_type_info const * ti = et.type_info_table->info[0];
|
||||
BOOST_ASSERT(ti!=0);
|
||||
return *ti;
|
||||
}
|
||||
|
||||
void
|
||||
copy_msvc_exception( void * dst, void * src, cpp_type_info const & ti )
|
||||
{
|
||||
if( !(ti.flags & class_is_simple_type) && ti.copy_constructor.normal_copy_constructor )
|
||||
{
|
||||
dummy_exception_type * dummy_exception_ptr = reinterpret_cast<dummy_exception_type *>(dst);
|
||||
if( ti.flags & class_has_virtual_base )
|
||||
(dummy_exception_ptr->*(ti.copy_constructor.copy_constructor_with_virtual_base))(src,dst);
|
||||
else
|
||||
(dummy_exception_ptr->*(ti.copy_constructor.normal_copy_constructor))(src);
|
||||
}
|
||||
else
|
||||
memmove(dst,src,ti.size);
|
||||
}
|
||||
|
||||
boost::shared_ptr<void>
|
||||
clone_msvc_exception( void * src, cpp_exception_type const & et )
|
||||
{
|
||||
assert(src!=0);
|
||||
cpp_type_info const & ti=get_cpp_type_info(et);
|
||||
if( void * dst = malloc(ti.size) )
|
||||
{
|
||||
try
|
||||
{
|
||||
copy_msvc_exception(dst,src,ti);
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
free(dst);
|
||||
throw;
|
||||
}
|
||||
return boost::shared_ptr<void>(dst,exception_object_deleter(et));
|
||||
}
|
||||
else
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
class
|
||||
cloned_exception:
|
||||
public boost::exception_detail::clone_base
|
||||
{
|
||||
cloned_exception( cloned_exception const & );
|
||||
cloned_exception & operator=( cloned_exception const & );
|
||||
|
||||
cpp_exception_type const & et_;
|
||||
boost::shared_ptr<void> exc_;
|
||||
|
||||
public:
|
||||
|
||||
cloned_exception( void * exc, cpp_exception_type const & et ):
|
||||
et_(et),
|
||||
exc_(clone_msvc_exception(exc,et_))
|
||||
{
|
||||
}
|
||||
|
||||
~cloned_exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
boost::exception_detail::clone_base const *
|
||||
clone() const
|
||||
{
|
||||
return new cloned_exception(exc_.get(),et_);
|
||||
}
|
||||
|
||||
void
|
||||
rethrow() const
|
||||
{
|
||||
cpp_type_info const & ti=get_cpp_type_info(et_);
|
||||
void * dst = _alloca(ti.size);
|
||||
copy_msvc_exception(dst,exc_.get(),ti);
|
||||
ULONG_PTR args[cpp_exception_parameter_count];
|
||||
args[0]=cpp_exception_magic_flag;
|
||||
args[1]=reinterpret_cast<ULONG_PTR>(dst);
|
||||
args[2]=reinterpret_cast<ULONG_PTR>(&et_);
|
||||
RaiseException(cpp_exception_code,EXCEPTION_NONCONTINUABLE,cpp_exception_parameter_count,args);
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
is_cpp_exception( EXCEPTION_RECORD const * record )
|
||||
{
|
||||
return record &&
|
||||
(record->ExceptionCode==cpp_exception_code) &&
|
||||
(record->NumberParameters==cpp_exception_parameter_count) &&
|
||||
(record->ExceptionInformation[0]==cpp_exception_magic_flag);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
exception_cloning_filter( int & result, boost::exception_detail::clone_base const * & ptr, void * info_ )
|
||||
{
|
||||
BOOST_ASSERT(exception_info_offset>=0);
|
||||
BOOST_ASSERT(info_!=0);
|
||||
EXCEPTION_POINTERS * info=reinterpret_cast<EXCEPTION_POINTERS *>(info_);
|
||||
EXCEPTION_RECORD * record=info->ExceptionRecord;
|
||||
if( is_cpp_exception(record) )
|
||||
{
|
||||
if( !record->ExceptionInformation[2] )
|
||||
record = *reinterpret_cast<EXCEPTION_RECORD * *>(reinterpret_cast<char *>(_errno())+exception_info_offset);
|
||||
if( is_cpp_exception(record) && record->ExceptionInformation[2] )
|
||||
try
|
||||
{
|
||||
ptr = new cloned_exception(
|
||||
reinterpret_cast<void *>(record->ExceptionInformation[1]),
|
||||
*reinterpret_cast<cpp_exception_type const *>(record->ExceptionInformation[2]));
|
||||
result = boost::exception_detail::clone_current_exception_result::success;
|
||||
}
|
||||
catch(
|
||||
std::bad_alloc & )
|
||||
{
|
||||
result = boost::exception_detail::clone_current_exception_result::bad_alloc;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
result = boost::exception_detail::clone_current_exception_result::bad_exception;
|
||||
}
|
||||
}
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
int
|
||||
clone_current_exception_non_intrusive( clone_base const * & cloned )
|
||||
{
|
||||
BOOST_ASSERT(!cloned);
|
||||
int result = clone_current_exception_result::not_supported;
|
||||
if( exception_info_offset>=0 )
|
||||
{
|
||||
clone_base const * ptr=0;
|
||||
__try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
__except(exception_cloning_filter(result,ptr,GetExceptionInformation()))
|
||||
{
|
||||
}
|
||||
if( result==clone_current_exception_result::success )
|
||||
cloned=ptr;
|
||||
}
|
||||
BOOST_ASSERT(result!=clone_current_exception_result::success || cloned);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//On all other compilers, return clone_current_exception_result::not_supported.
|
||||
//On such platforms, only the intrusive enable_current_exception() cloning will work.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
int
|
||||
clone_current_exception_non_intrusive( clone_base const * & )
|
||||
{
|
||||
return clone_current_exception_result::not_supported;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -7,7 +7,11 @@
|
||||
|
||||
import testing ;
|
||||
|
||||
project : requirements <exception-handling>on ;
|
||||
project
|
||||
: requirements
|
||||
<link>static
|
||||
<exception-handling>on
|
||||
;
|
||||
|
||||
#to_string
|
||||
|
||||
@ -36,7 +40,9 @@ run refcount_ptr_test.cpp ;
|
||||
run current_exception_cast_test.cpp ;
|
||||
run no_exceptions_test.cpp : : : <exception-handling>off ;
|
||||
run errinfos_test.cpp ;
|
||||
run exception_ptr_test.cpp/<define>BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR /boost/exception /boost//thread : : : <threading>multi : non_intrusive_exception_ptr_test ;
|
||||
run exception_ptr_test.cpp /boost//thread : : : <threading>multi ;
|
||||
|
||||
compile-fail exception_fail.cpp ;
|
||||
compile-fail throw_exception_fail.cpp ;
|
||||
compile-fail error_info_const_fail.cpp ;
|
||||
|
@ -146,6 +146,10 @@ test_std_exception()
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
T & )
|
||||
{
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
@ -176,7 +180,7 @@ test_std_exception_what()
|
||||
catch(
|
||||
T & x )
|
||||
{
|
||||
BOOST_TEST(std::string("what")==x.what());
|
||||
BOOST_TEST(std::string(x.what()).find("what")!=std::string::npos);
|
||||
boost::exception_ptr p = boost::current_exception();
|
||||
BOOST_TEST(!(p==boost::exception_ptr()));
|
||||
BOOST_TEST(p!=boost::exception_ptr());
|
||||
@ -189,7 +193,7 @@ test_std_exception_what()
|
||||
catch(
|
||||
T & x )
|
||||
{
|
||||
BOOST_TEST(std::string("what")==x.what());
|
||||
BOOST_TEST(std::string(x.what()).find("what")!=std::string::npos);
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
@ -216,6 +220,10 @@ test_std_exception_what()
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
T & )
|
||||
{
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
@ -385,6 +393,11 @@ main()
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
derives_std_exception & )
|
||||
{
|
||||
//Yay! Non-intrusive cloning supported!
|
||||
}
|
||||
catch(
|
||||
boost::unknown_exception & e )
|
||||
{
|
||||
#ifndef BOOST_NO_RTTI
|
||||
@ -434,6 +447,14 @@ main()
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
derives_std_boost_exception & x )
|
||||
{
|
||||
//Yay! Non-intrusive cloning supported!
|
||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||
if( int const * p=boost::get_error_info<my_info>(x) )
|
||||
BOOST_TEST(*p==42);
|
||||
}
|
||||
catch(
|
||||
boost::unknown_exception & x )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||
@ -495,6 +516,14 @@ main()
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
derives_boost_exception & x )
|
||||
{
|
||||
//Yay! Non-intrusive cloning supported!
|
||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||
if( int const * p=boost::get_error_info<my_info>(x) )
|
||||
BOOST_TEST(*p==42);
|
||||
}
|
||||
catch(
|
||||
boost::unknown_exception & x )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||
|
@ -6,15 +6,37 @@
|
||||
#include <boost/exception_ptr.hpp>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
typedef boost::error_info<struct tag_answer,int> answer;
|
||||
|
||||
boost::detail::atomic_count exc_count(0);
|
||||
|
||||
struct
|
||||
err:
|
||||
virtual boost::exception,
|
||||
virtual std::exception
|
||||
{
|
||||
err()
|
||||
{
|
||||
++exc_count;
|
||||
}
|
||||
|
||||
err( err const & )
|
||||
{
|
||||
++exc_count;
|
||||
}
|
||||
|
||||
virtual
|
||||
~err() throw()
|
||||
{
|
||||
--exc_count;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
err & operator=( err const & );
|
||||
};
|
||||
|
||||
class
|
||||
@ -116,7 +138,9 @@ simple_test()
|
||||
int
|
||||
main()
|
||||
{
|
||||
BOOST_TEST(++exc_count==1);
|
||||
simple_test();
|
||||
thread_test();
|
||||
BOOST_TEST(!--exc_count);
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -200,6 +200,17 @@ main()
|
||||
std::string di=current_exception_diagnostic_information();
|
||||
test3(di);
|
||||
}
|
||||
try
|
||||
{
|
||||
throw error4();
|
||||
}
|
||||
catch(
|
||||
error4 & x )
|
||||
{
|
||||
std::string di1=boost::diagnostic_information(x);
|
||||
std::string wh1=x.what();
|
||||
BOOST_TEST(wh1==di1);
|
||||
}
|
||||
try
|
||||
{
|
||||
error4 x; x << tagged_int1(42) << tagged_int2(42);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
@ -66,7 +67,34 @@ join( thread_handle & t )
|
||||
rethrow_exception(t.err_);
|
||||
}
|
||||
|
||||
struct exc: boost::exception, std::exception { };
|
||||
boost::detail::atomic_count exc_count(0);
|
||||
|
||||
struct
|
||||
exc:
|
||||
virtual boost::exception,
|
||||
virtual std::exception
|
||||
{
|
||||
exc()
|
||||
{
|
||||
++exc_count;
|
||||
}
|
||||
|
||||
exc( exc const & )
|
||||
{
|
||||
++exc_count;
|
||||
}
|
||||
|
||||
virtual
|
||||
~exc() throw()
|
||||
{
|
||||
--exc_count;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
exc & operator=( exc const & );
|
||||
};
|
||||
|
||||
typedef boost::error_info<struct answer_,int> answer;
|
||||
|
||||
void
|
||||
@ -93,6 +121,7 @@ check( boost::shared_ptr<thread_handle> const & t )
|
||||
int
|
||||
main()
|
||||
{
|
||||
BOOST_TEST(++exc_count==1);
|
||||
try
|
||||
{
|
||||
std::vector< boost::shared_ptr<thread_handle> > threads;
|
||||
@ -109,4 +138,5 @@ main()
|
||||
boost::current_exception_diagnostic_information() << std::endl;
|
||||
return 42;
|
||||
}
|
||||
BOOST_TEST(!--exc_count);
|
||||
}
|
||||
|
@ -62,6 +62,15 @@ main()
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
//Yay! Non-intrusive cloning supported!
|
||||
if( int const * d=boost::get_error_info<test>(x) )
|
||||
BOOST_TEST( 42==*d );
|
||||
else
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
@ -101,6 +110,11 @@ main()
|
||||
{
|
||||
}
|
||||
catch(
|
||||
std::exception & )
|
||||
{
|
||||
//Yay! Non-intrusive cloning supported!
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
@ -114,6 +128,11 @@ main()
|
||||
{
|
||||
}
|
||||
catch(
|
||||
std::exception & )
|
||||
{
|
||||
//Yay! Non-intrusive cloning supported!
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
|
Reference in New Issue
Block a user