forked from boostorg/container
Fixes #184 ("Issues with custom exceptions implementation")
This commit is contained in:
@@ -27,22 +27,27 @@
|
||||
#include <exception> //for std exception base
|
||||
|
||||
# if defined(BOOST_CONTAINER_USE_STD_EXCEPTIONS)
|
||||
#include <stdexcept> //for std exception types
|
||||
#include <stdexcept> //for std::out_of_range, std::length_error, std::logic_error, std::runtime_error
|
||||
#include <string> //for implicit std::string conversion
|
||||
#include <new> //for std::bad_alloc
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
typedef std::bad_alloc bad_alloc_t;
|
||||
typedef std::out_of_range out_of_range_t;
|
||||
typedef std::out_of_range length_error_t;
|
||||
typedef std::length_error length_error_t;
|
||||
typedef std::logic_error logic_error_t;
|
||||
typedef std::runtime_error runtime_error_t;
|
||||
|
||||
}} //namespace boost::container
|
||||
|
||||
# else //!BOOST_CONTAINER_USE_STD_EXCEPTIONS
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
class exception
|
||||
class BOOST_SYMBOL_EXPORT exception
|
||||
: public ::std::exception
|
||||
{
|
||||
typedef ::std::exception std_exception_t;
|
||||
@@ -61,7 +66,7 @@ class exception
|
||||
const char *m_msg;
|
||||
};
|
||||
|
||||
class bad_alloc
|
||||
class BOOST_SYMBOL_EXPORT bad_alloc
|
||||
: public exception
|
||||
{
|
||||
public:
|
||||
@@ -72,7 +77,7 @@ class bad_alloc
|
||||
|
||||
typedef bad_alloc bad_alloc_t;
|
||||
|
||||
class out_of_range
|
||||
class BOOST_SYMBOL_EXPORT out_of_range
|
||||
: public exception
|
||||
{
|
||||
public:
|
||||
@@ -83,7 +88,7 @@ class out_of_range
|
||||
|
||||
typedef out_of_range out_of_range_t;
|
||||
|
||||
class length_error
|
||||
class BOOST_SYMBOL_EXPORT length_error
|
||||
: public exception
|
||||
{
|
||||
public:
|
||||
@@ -94,7 +99,7 @@ class length_error
|
||||
|
||||
typedef out_of_range length_error_t;
|
||||
|
||||
class logic_error
|
||||
class BOOST_SYMBOL_EXPORT logic_error
|
||||
: public exception
|
||||
{
|
||||
public:
|
||||
@@ -105,7 +110,7 @@ class logic_error
|
||||
|
||||
typedef logic_error logic_error_t;
|
||||
|
||||
class runtime_error
|
||||
class BOOST_SYMBOL_EXPORT runtime_error
|
||||
: public exception
|
||||
{
|
||||
public:
|
||||
@@ -181,7 +186,11 @@ namespace container {
|
||||
|
||||
//! Exception callback called by Boost.Container when fails to allocate the requested storage space.
|
||||
//! <ul>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::bad_alloc()</code> is thrown.</li>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
|
||||
//! <code>boost::container::bad_alloc(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
|
||||
//! <code>std::bad_alloc(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
|
||||
//! is NOT defined <code>BOOST_ASSERT(!"boost::container bad_alloc thrown")</code> is called
|
||||
@@ -192,16 +201,16 @@ namespace container {
|
||||
//! </ul>
|
||||
BOOST_NORETURN inline void throw_bad_alloc()
|
||||
{
|
||||
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
|
||||
throw std::bad_alloc();
|
||||
#else
|
||||
throw bad_alloc();
|
||||
#endif
|
||||
throw bad_alloc_t();
|
||||
}
|
||||
|
||||
//! Exception callback called by Boost.Container to signal arguments out of range.
|
||||
//! <ul>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::out_of_range(str)</code> is thrown.</li>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
|
||||
//! <code>boost::container::out_of_range(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
|
||||
//! <code>std::out_of_range(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
|
||||
//! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str)</code> is called
|
||||
@@ -212,16 +221,17 @@ namespace container {
|
||||
//! </ul>
|
||||
BOOST_NORETURN inline void throw_out_of_range(const char* str)
|
||||
{
|
||||
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
|
||||
throw std::out_of_range(str);
|
||||
#else
|
||||
throw out_of_range(str);
|
||||
#endif
|
||||
throw out_of_range_t(str);
|
||||
}
|
||||
|
||||
//! Exception callback called by Boost.Container to signal errors resizing.
|
||||
//! <ul>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::length_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
|
||||
//! <code>boost::container::length_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
|
||||
//! <code>std::length_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
|
||||
//! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container length_error thrown", str)</code> is called
|
||||
@@ -232,17 +242,18 @@ namespace container {
|
||||
//! </ul>
|
||||
BOOST_NORETURN inline void throw_length_error(const char* str)
|
||||
{
|
||||
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
|
||||
throw std::length_error(str);
|
||||
#else
|
||||
throw length_error(str);
|
||||
#endif
|
||||
throw length_error_t(str);
|
||||
}
|
||||
|
||||
//! Exception callback called by Boost.Container to report errors in the internal logical
|
||||
//! of the program, such as violation of logical preconditions or class invariants.
|
||||
//! <ul>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::logic_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
|
||||
//! <code>boost::container::logic_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
|
||||
//! <code>std::logic_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
|
||||
//! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str)</code> is called
|
||||
@@ -253,16 +264,16 @@ namespace container {
|
||||
//! </ul>
|
||||
BOOST_NORETURN inline void throw_logic_error(const char* str)
|
||||
{
|
||||
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
|
||||
throw std::logic_error(str);
|
||||
#else
|
||||
throw logic_error(str);
|
||||
#endif
|
||||
throw logic_error_t(str);
|
||||
}
|
||||
|
||||
//! Exception callback called by Boost.Container to report errors that can only be detected during runtime.
|
||||
//! <ul>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::runtime_error(str)</code> is thrown.</li>
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
|
||||
//! <code>boost::container::runtime_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
|
||||
//! <code>std::runtime_error(str)</code> is thrown.</li>
|
||||
//!
|
||||
//! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
|
||||
//! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str)</code> is called
|
||||
@@ -273,11 +284,7 @@ namespace container {
|
||||
//! </ul>
|
||||
BOOST_NORETURN inline void throw_runtime_error(const char* str)
|
||||
{
|
||||
#ifdef BOOST_CONTAINER_USE_STD_EXCEPTIONS
|
||||
throw std::runtime_error(str);
|
||||
#else
|
||||
throw runtime_error(str);
|
||||
#endif
|
||||
throw runtime_error_t(str);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user