throw_exception.hpp
9.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2012-2013. 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)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
#define BOOST_CONTAINER_THROW_EXCEPTION_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
#include <boost/core/ignore_unused.hpp>
#ifndef BOOST_NO_EXCEPTIONS
#include <exception> //for std exception base
# if defined(BOOST_CONTAINER_USE_STD_EXCEPTIONS)
#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::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 BOOST_SYMBOL_VISIBLE exception
: public ::std::exception
{
typedef ::std::exception std_exception_t;
public:
//msg must be a static string (guaranteed by callers)
explicit exception(const char *msg)
: std_exception_t(), m_msg(msg)
{}
virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return m_msg ? m_msg : "unknown boost::container exception"; }
private:
const char *m_msg;
};
class BOOST_SYMBOL_VISIBLE bad_alloc
: public exception
{
public:
bad_alloc()
: exception("boost::container::bad_alloc thrown")
{}
};
typedef bad_alloc bad_alloc_t;
class BOOST_SYMBOL_VISIBLE out_of_range
: public exception
{
public:
explicit out_of_range(const char *msg)
: exception(msg)
{}
};
typedef out_of_range out_of_range_t;
class BOOST_SYMBOL_VISIBLE length_error
: public exception
{
public:
explicit length_error(const char *msg)
: exception(msg)
{}
};
typedef length_error length_error_t;
class BOOST_SYMBOL_VISIBLE logic_error
: public exception
{
public:
explicit logic_error(const char *msg)
: exception(msg)
{}
};
typedef logic_error logic_error_t;
class BOOST_SYMBOL_VISIBLE runtime_error
: public exception
{
public:
explicit runtime_error(const char *msg)
: exception(msg)
{}
};
typedef runtime_error runtime_error_t;
} // namespace boost {
} // namespace container {
# endif
#else
#include <boost/assert.hpp>
#include <cstdlib> //for std::abort
#endif
namespace boost {
namespace container {
#if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
//The user must provide definitions for the following functions
BOOST_NORETURN void throw_bad_alloc();
BOOST_NORETURN void throw_out_of_range(const char* str);
BOOST_NORETURN void throw_length_error(const char* str);
BOOST_NORETURN void throw_logic_error(const char* str);
BOOST_NORETURN void throw_runtime_error(const char* str);
#elif defined(BOOST_NO_EXCEPTIONS)
BOOST_NORETURN inline void throw_bad_alloc()
{
BOOST_ASSERT(!"boost::container bad_alloc thrown");
std::abort();
}
BOOST_NORETURN inline void throw_out_of_range(const char* str)
{
boost::ignore_unused(str);
BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str);
std::abort();
}
BOOST_NORETURN inline void throw_length_error(const char* str)
{
boost::ignore_unused(str);
BOOST_ASSERT_MSG(!"boost::container length_error thrown", str);
std::abort();
}
BOOST_NORETURN inline void throw_logic_error(const char* str)
{
boost::ignore_unused(str);
BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str);
std::abort();
}
BOOST_NORETURN inline void throw_runtime_error(const char* str)
{
boost::ignore_unused(str);
BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str);
std::abort();
}
#else //defined(BOOST_NO_EXCEPTIONS)
//! Exception callback called by Boost.Container when fails to allocate the requested storage space.
//! <ul>
//! <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
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
BOOST_NORETURN inline void throw_bad_alloc()
{
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 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
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
BOOST_NORETURN inline void throw_out_of_range(const char* str)
{
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 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
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
BOOST_NORETURN inline void throw_length_error(const char* str)
{
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 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
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
BOOST_NORETURN inline void throw_logic_error(const char* str)
{
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 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
//! and <code>std::abort()</code> if the former returns.</li>
//!
//! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
//! the user must provide an implementation and the function should not return.</li>
//! </ul>
BOOST_NORETURN inline void throw_runtime_error(const char* str)
{
throw runtime_error_t(str);
}
#endif
}} //namespace boost { namespace container {
#include <boost/container/detail/config_end.hpp>
#endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP