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 const char msg[] = "boost::container bad_alloc thrown";
60 inline void throw_out_of_range(const char* str)
62 const char msg[] = "boost::container out_of_range thrown";
64 BOOST_ASSERT_MSG(!msg, str);
68 inline void throw_length_error(const char* str)
70 const char msg[] = "boost::container length_error thrown";
72 BOOST_ASSERT_MSG(!msg, str);
76 inline void throw_logic_error(const char* str)
78 const char msg[] = "boost::container logic_error thrown";
80 BOOST_ASSERT_MSG(!msg, str);
84 inline void throw_runtime_error(const char* str)
86 const char msg[] = "boost::container runtime_error thrown";
88 BOOST_ASSERT_MSG(!msg, str);
92 #else //defined(BOOST_NO_EXCEPTIONS)
94 //! Exception callback called by Boost.Container when fails to allocate the requested storage space.
96 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::bad_alloc()</code> is thrown.</li>
98 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
99 //! is NOT defined <code>BOOST_ASSERT(!"boost::container bad_alloc thrown")</code> is called
100 //! and <code>std::abort()</code> if the former returns.</li>
102 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
103 //! the user must provide an implementation and the function should not return.</li>
105 inline void throw_bad_alloc()
107 throw std::bad_alloc();
110 //! Exception callback called by Boost.Container to signal arguments out of range.
112 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::out_of_range(str)</code> is thrown.</li>
114 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
115 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str)</code> is called
116 //! and <code>std::abort()</code> if the former returns.</li>
118 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
119 //! the user must provide an implementation and the function should not return.</li>
121 inline void throw_out_of_range(const char* str)
123 throw std::out_of_range(str);
126 //! Exception callback called by Boost.Container to signal errors resizing.
128 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::length_error(str)</code> is thrown.</li>
130 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
131 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container length_error thrown", str)</code> is called
132 //! and <code>std::abort()</code> if the former returns.</li>
134 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
135 //! the user must provide an implementation and the function should not return.</li>
137 inline void throw_length_error(const char* str)
139 throw std::length_error(str);
142 //! Exception callback called by Boost.Container to report errors in the internal logical
143 //! of the program, such as violation of logical preconditions or class invariants.
145 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::logic_error(str)</code> is thrown.</li>
147 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
148 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str)</code> is called
149 //! and <code>std::abort()</code> if the former returns.</li>
151 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
152 //! the user must provide an implementation and the function should not return.</li>
154 inline void throw_logic_error(const char* str)
156 throw std::logic_error(str);
159 //! Exception callback called by Boost.Container to report errors that can only be detected during runtime.
161 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined <code>std::runtime_error(str)</code> is thrown.</li>
163 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
164 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str)</code> is called
165 //! and <code>std::abort()</code> if the former returns.</li>
167 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
168 //! the user must provide an implementation and the function should not return.</li>
170 inline void throw_runtime_error(const char* str)
172 throw std::runtime_error(str);
177 }} //namespace boost { namespace container {
179 #include <boost/container/detail/config_end.hpp>
181 #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP