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)
9 * \author Andrey Semashev
12 * The header contains exception classes declarations.
15 #ifndef BOOST_LOG_EXCEPTIONS_HPP_INCLUDED_
16 #define BOOST_LOG_EXCEPTIONS_HPP_INCLUDED_
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>
29 #ifdef BOOST_HAS_PRAGMA_ONCE
35 // Forward-declaration of an exception base class from Boost.Exception
37 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
38 # pragma GCC visibility push (default)
42 # pragma GCC visibility pop
50 class BOOST_SYMBOL_VISIBLE exception;
54 BOOST_LOG_OPEN_NAMESPACE
58 //! Attaches attribute name exception information
59 BOOST_LOG_API void attach_attribute_name_info(exception& e, attribute_name const& name);
64 * \brief Base class for memory allocation errors
66 * Exceptions derived from this class indicate problems with memory allocation.
68 class BOOST_LOG_API bad_alloc :
72 std::string m_message;
76 * Initializing constructor. Creates an exception with the specified error message.
78 explicit bad_alloc(const char* descr);
80 * Initializing constructor. Creates an exception with the specified error message.
82 explicit bad_alloc(std::string const& descr);
86 ~bad_alloc() throw() BOOST_OVERRIDE;
89 * Error message accessor.
91 const char* what() const throw() BOOST_OVERRIDE;
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);
100 * \brief The exception is used to indicate reaching a storage capacity limit
102 class BOOST_LOG_API capacity_limit_reached :
107 * Initializing constructor. Creates an exception with the specified error message.
109 explicit capacity_limit_reached(const char* descr);
111 * Initializing constructor. Creates an exception with the specified error message.
113 explicit capacity_limit_reached(std::string const& descr);
117 ~capacity_limit_reached() throw() BOOST_OVERRIDE;
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);
126 * \brief Base class for runtime exceptions from the logging library
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.
132 class BOOST_LOG_API runtime_error :
133 public std::runtime_error
137 * Initializing constructor. Creates an exception with the specified error message.
139 explicit runtime_error(std::string const& descr);
143 ~runtime_error() throw() BOOST_OVERRIDE;
147 * \brief Exception class that is used to indicate errors of missing values
149 class BOOST_LOG_API missing_value :
154 * Default constructor. Creates an exception with the default error message.
158 * Initializing constructor. Creates an exception with the specified error message.
160 explicit missing_value(std::string const& descr);
164 ~missing_value() throw() BOOST_OVERRIDE;
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);
176 * \brief Exception class that is used to indicate errors of incorrect type of an object
178 class BOOST_LOG_API invalid_type :
183 * Default constructor. Creates an exception with the default error message.
187 * Initializing constructor. Creates an exception with the specified error message.
189 explicit invalid_type(std::string const& descr);
193 ~invalid_type() throw() BOOST_OVERRIDE;
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);
209 * \brief Exception class that is used to indicate errors of incorrect value of an object
211 class BOOST_LOG_API invalid_value :
216 * Default constructor. Creates an exception with the default error message.
220 * Initializing constructor. Creates an exception with the specified error message.
222 explicit invalid_value(std::string const& descr);
226 ~invalid_value() throw() BOOST_OVERRIDE;
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);
236 * \brief Exception class that is used to indicate parsing errors
238 class BOOST_LOG_API parse_error :
243 * Default constructor. Creates an exception with the default error message.
247 * Initializing constructor. Creates an exception with the specified error message.
249 explicit parse_error(std::string const& descr);
253 ~parse_error() throw() BOOST_OVERRIDE;
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);
267 * \brief Exception class that is used to indicate conversion errors
269 class BOOST_LOG_API conversion_error :
274 * Default constructor. Creates an exception with the default error message.
278 * Initializing constructor. Creates an exception with the specified error message.
280 explicit conversion_error(std::string const& descr);
284 ~conversion_error() throw() BOOST_OVERRIDE;
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);
294 * \brief Exception class that is used to indicate underlying OS API errors
296 class BOOST_LOG_API system_error :
297 public boost::system::system_error
301 * Initializing constructor. Creates an exception with the specified error message.
303 system_error(boost::system::error_code code, std::string const& descr);
307 ~system_error() throw() BOOST_OVERRIDE;
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);
318 * \brief Base class for logic exceptions from the logging library
320 * Exceptions derived from this class usually indicate errors on the user's side, such as
321 * incorrect library usage.
323 class BOOST_LOG_API logic_error :
324 public std::logic_error
328 * Initializing constructor. Creates an exception with the specified error message.
330 explicit logic_error(std::string const& descr);
334 ~logic_error() throw() BOOST_OVERRIDE;
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);
343 * \brief Exception class that is used to indicate ODR violation
345 class BOOST_LOG_API odr_violation :
350 * Default constructor. Creates an exception with the default error message.
354 * Initializing constructor. Creates an exception with the specified error message.
356 explicit odr_violation(std::string const& descr);
360 ~odr_violation() throw() BOOST_OVERRIDE;
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);
370 * \brief Exception class that is used to indicate invalid call sequence
372 class BOOST_LOG_API unexpected_call :
377 * Default constructor. Creates an exception with the default error message.
381 * Initializing constructor. Creates an exception with the specified error message.
383 explicit unexpected_call(std::string const& descr);
387 ~unexpected_call() throw() BOOST_OVERRIDE;
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);
397 * \brief Exception class that is used to indicate invalid library setup
399 class BOOST_LOG_API setup_error :
404 * Default constructor. Creates an exception with the default error message.
408 * Initializing constructor. Creates an exception with the specified error message.
410 explicit setup_error(std::string const& descr);
414 ~setup_error() throw() BOOST_OVERRIDE;
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);
424 * \brief Exception class that is used to indicate library limitation
426 class BOOST_LOG_API limitation_error :
431 * Default constructor. Creates an exception with the default error message.
435 * Initializing constructor. Creates an exception with the specified error message.
437 explicit limitation_error(std::string const& descr);
441 ~limitation_error() throw() BOOST_OVERRIDE;
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);
450 BOOST_LOG_CLOSE_NAMESPACE // namespace log
454 #ifndef BOOST_LOG_DOXYGEN_PASS
456 #define BOOST_LOG_THROW(ex)\
457 ex::throw_(__FILE__, static_cast< std::size_t >(__LINE__))
459 #define BOOST_LOG_THROW_DESCR(ex, descr)\
460 ex::throw_(__FILE__, static_cast< std::size_t >(__LINE__), descr)
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))
465 #endif // BOOST_LOG_DOXYGEN_PASS
467 #include <boost/log/detail/footer.hpp>
469 #endif // BOOST_LOG_EXCEPTIONS_HPP_INCLUDED_