1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
12 #define BOOST_CONTAINER_THROW_EXCEPTION_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
25 #ifndef BOOST_NO_EXCEPTIONS
26 #include <stdexcept> //for std exception types
27 #include <string> //for implicit std::string conversion
28 #include <new> //for std::bad_alloc
30 #include <boost/assert.hpp>
31 #include <cstdlib> //for std::abort
37 #if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
38 //The user must provide definitions for the following functions
40 void throw_bad_alloc();
42 void throw_out_of_range(const char* str);
44 void throw_length_error(const char* str);
46 void throw_logic_error(const char* str);
48 void throw_runtime_error(const char* str);
50 #elif defined(BOOST_NO_EXCEPTIONS)
52 inline void throw_bad_alloc()
54 BOOST_ASSERT(!"boost::container bad_alloc thrown");
58 inline void throw_out_of_range(const char* str)
60 BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str);
64 inline void throw_length_error(const char* str)
66 BOOST_ASSERT_MSG(!"boost::container length_error thrown", str);
70 inline void throw_logic_error(const char* str)
72 BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str);
76 inline void throw_runtime_error(const char* str)
78 BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str);
82 #else //defined(BOOST_NO_EXCEPTIONS)
84 //! Exception callback called by Boost.Container when fails to allocate the requested storage space.
86 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::bad_alloc()</code> is thrown.</li>
88 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
89 //! is NOT defined <code>BOOST_ASSERT(!"boost::container bad_alloc thrown")</code> is called
90 //! and <code>std::abort()</code> if the former returns.</li>
92 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
93 //! the user must provide an implementation and the function should not return.</li>
95 inline void throw_bad_alloc()
97 throw std::bad_alloc();
100 //! Exception callback called by Boost.Container to signal arguments out of range.
102 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::out_of_range(str)</code> is thrown.</li>
104 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
105 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str)</code> is called
106 //! and <code>std::abort()</code> if the former returns.</li>
108 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
109 //! the user must provide an implementation and the function should not return.</li>
111 inline void throw_out_of_range(const char* str)
113 throw std::out_of_range(str);
116 //! Exception callback called by Boost.Container to signal errors resizing.
118 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::length_error(str)</code> is thrown.</li>
120 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
121 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container length_error thrown", str)</code> is called
122 //! and <code>std::abort()</code> if the former returns.</li>
124 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
125 //! the user must provide an implementation and the function should not return.</li>
127 inline void throw_length_error(const char* str)
129 throw std::length_error(str);
132 //! Exception callback called by Boost.Container to report errors in the internal logical
133 //! of the program, such as violation of logical preconditions or class invariants.
135 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::logic_error(str)</code> is thrown.</li>
137 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
138 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str)</code> is called
139 //! and <code>std::abort()</code> if the former returns.</li>
141 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
142 //! the user must provide an implementation and the function should not return.</li>
144 inline void throw_logic_error(const char* str)
146 throw std::logic_error(str);
149 //! Exception callback called by Boost.Container to report errors that can only be detected during runtime.
151 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::runtime_error(str)</code> is thrown.</li>
153 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
154 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str)</code> is called
155 //! and <code>std::abort()</code> if the former returns.</li>
157 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
158 //! the user must provide an implementation and the function should not return.</li>
160 inline void throw_runtime_error(const char* str)
162 throw std::runtime_error(str);
167 }} //namespace boost { namespace container {
169 #include <boost/container/detail/config_end.hpp>
171 #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP