1/*
2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
6 */
7/*!
8 * \file
9 * \author Andrey Semashev
10 * \date 31.10.2009
11 *
12 * The header contains exception classes declarations.
13 */
14
15#ifndef BOOST_LOG_EXCEPTIONS_HPP_INCLUDED_
16#define BOOST_LOG_EXCEPTIONS_HPP_INCLUDED_
17
18#include <cstddef>
19#include <string>
20#include <stdexcept>
21#include <boost/type_index.hpp>
22#include <boost/preprocessor/seq/enum.hpp>
23#include <boost/system/error_code.hpp>
24#include <boost/system/system_error.hpp>
25#include <boost/log/detail/config.hpp>
26#include <boost/log/attributes/attribute_name.hpp>
27#include <boost/log/detail/header.hpp>
28
29#ifdef BOOST_HAS_PRAGMA_ONCE
30#pragma once
31#endif
32
33namespace boost {
34
35// Forward-declaration of an exception base class from Boost.Exception
36#if defined(__GNUC__)
37# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
38# pragma GCC visibility push (default)
39
40class exception;
41
42# pragma GCC visibility pop
43# else
44
45class exception;
46
47# endif
48#else
49
50class BOOST_SYMBOL_VISIBLE exception;
51
52#endif
53
54BOOST_LOG_OPEN_NAMESPACE
55
56namespace aux {
57
58//! Attaches attribute name exception information
59BOOST_LOG_API void attach_attribute_name_info(exception& e, attribute_name const& name);
60
61} // namespace aux
62
63/*!
64 * \brief Base class for memory allocation errors
65 *
66 * Exceptions derived from this class indicate problems with memory allocation.
67 */
68class BOOST_LOG_API bad_alloc :
69 public std::bad_alloc
70{
71private:
72 std::string m_message;
73
74public:
75 /*!
76 * Initializing constructor. Creates an exception with the specified error message.
77 */
78 explicit bad_alloc(const char* descr);
79 /*!
80 * Initializing constructor. Creates an exception with the specified error message.
81 */
82 explicit bad_alloc(std::string const& descr);
83 /*!
84 * Destructor
85 */
86 ~bad_alloc() throw() BOOST_OVERRIDE;
87
88 /*!
89 * Error message accessor.
90 */
91 const char* what() const throw() BOOST_OVERRIDE;
92
93#ifndef BOOST_LOG_DOXYGEN_PASS
94 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
95 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
96#endif
97};
98
99/*!
100 * \brief The exception is used to indicate reaching a storage capacity limit
101 */
102class BOOST_LOG_API capacity_limit_reached :
103 public bad_alloc
104{
105public:
106 /*!
107 * Initializing constructor. Creates an exception with the specified error message.
108 */
109 explicit capacity_limit_reached(const char* descr);
110 /*!
111 * Initializing constructor. Creates an exception with the specified error message.
112 */
113 explicit capacity_limit_reached(std::string const& descr);
114 /*!
115 * Destructor
116 */
117 ~capacity_limit_reached() throw() BOOST_OVERRIDE;
118
119#ifndef BOOST_LOG_DOXYGEN_PASS
120 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
121 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
122#endif
123};
124
125/*!
126 * \brief Base class for runtime exceptions from the logging library
127 *
128 * Exceptions derived from this class indicate a problem that may not directly
129 * be caused by the user's code that interacts with the library, such as
130 * errors caused by input data.
131 */
132class BOOST_LOG_API runtime_error :
133 public std::runtime_error
134{
135public:
136 /*!
137 * Initializing constructor. Creates an exception with the specified error message.
138 */
139 explicit runtime_error(std::string const& descr);
140 /*!
141 * Destructor
142 */
143 ~runtime_error() throw() BOOST_OVERRIDE;
144};
145
146/*!
147 * \brief Exception class that is used to indicate errors of missing values
148 */
149class BOOST_LOG_API missing_value :
150 public runtime_error
151{
152public:
153 /*!
154 * Default constructor. Creates an exception with the default error message.
155 */
156 missing_value();
157 /*!
158 * Initializing constructor. Creates an exception with the specified error message.
159 */
160 explicit missing_value(std::string const& descr);
161 /*!
162 * Destructor
163 */
164 ~missing_value() throw() BOOST_OVERRIDE;
165
166#ifndef BOOST_LOG_DOXYGEN_PASS
167 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
168 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
169 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
170 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name);
171 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name);
172#endif
173};
174
175/*!
176 * \brief Exception class that is used to indicate errors of incorrect type of an object
177 */
178class BOOST_LOG_API invalid_type :
179 public runtime_error
180{
181public:
182 /*!
183 * Default constructor. Creates an exception with the default error message.
184 */
185 invalid_type();
186 /*!
187 * Initializing constructor. Creates an exception with the specified error message.
188 */
189 explicit invalid_type(std::string const& descr);
190 /*!
191 * Destructor
192 */
193 ~invalid_type() throw() BOOST_OVERRIDE;
194
195#ifndef BOOST_LOG_DOXYGEN_PASS
196 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
197 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
198 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
199 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name);
200 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name);
201 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, typeindex::type_index const& type);
202 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, typeindex::type_index const& type);
203 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name, typeindex::type_index const& type);
204 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name, typeindex::type_index const& type);
205#endif
206};
207
208/*!
209 * \brief Exception class that is used to indicate errors of incorrect value of an object
210 */
211class BOOST_LOG_API invalid_value :
212 public runtime_error
213{
214public:
215 /*!
216 * Default constructor. Creates an exception with the default error message.
217 */
218 invalid_value();
219 /*!
220 * Initializing constructor. Creates an exception with the specified error message.
221 */
222 explicit invalid_value(std::string const& descr);
223 /*!
224 * Destructor
225 */
226 ~invalid_value() throw() BOOST_OVERRIDE;
227
228#ifndef BOOST_LOG_DOXYGEN_PASS
229 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
230 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
231 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
232#endif
233};
234
235/*!
236 * \brief Exception class that is used to indicate parsing errors
237 */
238class BOOST_LOG_API parse_error :
239 public runtime_error
240{
241public:
242 /*!
243 * Default constructor. Creates an exception with the default error message.
244 */
245 parse_error();
246 /*!
247 * Initializing constructor. Creates an exception with the specified error message.
248 */
249 explicit parse_error(std::string const& descr);
250 /*!
251 * Destructor
252 */
253 ~parse_error() throw() BOOST_OVERRIDE;
254
255#ifndef BOOST_LOG_DOXYGEN_PASS
256 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
257 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
258 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
259 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, std::size_t content_line);
260 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, std::size_t content_line);
261 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name);
262 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name);
263#endif
264};
265
266/*!
267 * \brief Exception class that is used to indicate conversion errors
268 */
269class BOOST_LOG_API conversion_error :
270 public runtime_error
271{
272public:
273 /*!
274 * Default constructor. Creates an exception with the default error message.
275 */
276 conversion_error();
277 /*!
278 * Initializing constructor. Creates an exception with the specified error message.
279 */
280 explicit conversion_error(std::string const& descr);
281 /*!
282 * Destructor
283 */
284 ~conversion_error() throw() BOOST_OVERRIDE;
285
286#ifndef BOOST_LOG_DOXYGEN_PASS
287 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
288 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
289 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
290#endif
291};
292
293/*!
294 * \brief Exception class that is used to indicate underlying OS API errors
295 */
296class BOOST_LOG_API system_error :
297 public boost::system::system_error
298{
299public:
300 /*!
301 * Initializing constructor. Creates an exception with the specified error message.
302 */
303 system_error(boost::system::error_code code, std::string const& descr);
304 /*!
305 * Destructor
306 */
307 ~system_error() throw() BOOST_OVERRIDE;
308
309#ifndef BOOST_LOG_DOXYGEN_PASS
310 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, int system_error_code);
311 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, int system_error_code);
312 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr, boost::system::error_code code);
313 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, boost::system::error_code code);
314#endif
315};
316
317/*!
318 * \brief Base class for logic exceptions from the logging library
319 *
320 * Exceptions derived from this class usually indicate errors on the user's side, such as
321 * incorrect library usage.
322 */
323class BOOST_LOG_API logic_error :
324 public std::logic_error
325{
326public:
327 /*!
328 * Initializing constructor. Creates an exception with the specified error message.
329 */
330 explicit logic_error(std::string const& descr);
331 /*!
332 * Destructor
333 */
334 ~logic_error() throw() BOOST_OVERRIDE;
335
336#ifndef BOOST_LOG_DOXYGEN_PASS
337 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
338 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
339#endif
340};
341
342/*!
343 * \brief Exception class that is used to indicate ODR violation
344 */
345class BOOST_LOG_API odr_violation :
346 public logic_error
347{
348public:
349 /*!
350 * Default constructor. Creates an exception with the default error message.
351 */
352 odr_violation();
353 /*!
354 * Initializing constructor. Creates an exception with the specified error message.
355 */
356 explicit odr_violation(std::string const& descr);
357 /*!
358 * Destructor
359 */
360 ~odr_violation() throw() BOOST_OVERRIDE;
361
362#ifndef BOOST_LOG_DOXYGEN_PASS
363 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
364 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
365 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
366#endif
367};
368
369/*!
370 * \brief Exception class that is used to indicate invalid call sequence
371 */
372class BOOST_LOG_API unexpected_call :
373 public logic_error
374{
375public:
376 /*!
377 * Default constructor. Creates an exception with the default error message.
378 */
379 unexpected_call();
380 /*!
381 * Initializing constructor. Creates an exception with the specified error message.
382 */
383 explicit unexpected_call(std::string const& descr);
384 /*!
385 * Destructor
386 */
387 ~unexpected_call() throw() BOOST_OVERRIDE;
388
389#ifndef BOOST_LOG_DOXYGEN_PASS
390 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
391 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
392 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
393#endif
394};
395
396/*!
397 * \brief Exception class that is used to indicate invalid library setup
398 */
399class BOOST_LOG_API setup_error :
400 public logic_error
401{
402public:
403 /*!
404 * Default constructor. Creates an exception with the default error message.
405 */
406 setup_error();
407 /*!
408 * Initializing constructor. Creates an exception with the specified error message.
409 */
410 explicit setup_error(std::string const& descr);
411 /*!
412 * Destructor
413 */
414 ~setup_error() throw() BOOST_OVERRIDE;
415
416#ifndef BOOST_LOG_DOXYGEN_PASS
417 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
418 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
419 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
420#endif
421};
422
423/*!
424 * \brief Exception class that is used to indicate library limitation
425 */
426class BOOST_LOG_API limitation_error :
427 public logic_error
428{
429public:
430 /*!
431 * Default constructor. Creates an exception with the default error message.
432 */
433 limitation_error();
434 /*!
435 * Initializing constructor. Creates an exception with the specified error message.
436 */
437 explicit limitation_error(std::string const& descr);
438 /*!
439 * Destructor
440 */
441 ~limitation_error() throw() BOOST_OVERRIDE;
442
443#ifndef BOOST_LOG_DOXYGEN_PASS
444 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
445 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, const char* descr);
446 static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
447#endif
448};
449
450BOOST_LOG_CLOSE_NAMESPACE // namespace log
451
452} // namespace boost
453
454#ifndef BOOST_LOG_DOXYGEN_PASS
455
456#define BOOST_LOG_THROW(ex)\
457 ex::throw_(__FILE__, static_cast< std::size_t >(__LINE__))
458
459#define BOOST_LOG_THROW_DESCR(ex, descr)\
460 ex::throw_(__FILE__, static_cast< std::size_t >(__LINE__), descr)
461
462#define BOOST_LOG_THROW_DESCR_PARAMS(ex, descr, params)\
463 ex::throw_(__FILE__, static_cast< std::size_t >(__LINE__), descr, BOOST_PP_SEQ_ENUM(params))
464
465#endif // BOOST_LOG_DOXYGEN_PASS
466
467#include <boost/log/detail/footer.hpp>
468
469#endif // BOOST_LOG_EXCEPTIONS_HPP_INCLUDED_
470

source code of boost/libs/log/include/boost/log/exceptions.hpp