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 exceptions.cpp
9 * \author Andrey Semashev
10 * \date 31.10.2009
11 *
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
14 */
15
16 #include <boost/log/detail/config.hpp>
17 #include <boost/throw_exception.hpp>
18 #include <boost/exception/exception.hpp>
19 #include <boost/exception/errinfo_at_line.hpp>
20 #include <boost/exception/info.hpp>
21 #include <boost/log/exceptions.hpp>
22 #include <boost/log/support/exception.hpp>
23 #include <boost/log/detail/header.hpp>
24
25 #ifdef _MSC_VER
26 #pragma warning(push)
27 // conversion from 'size_t' to 'boost::error_info<boost::throw_line_,int>::value_type', possible loss of data
28 // No idea why line number is stored as a signed integer in the error info...
29 #pragma warning(disable: 4267)
30 #endif
31
32 namespace boost {
33
34 BOOST_LOG_OPEN_NAMESPACE
35
36 namespace aux {
37
38 //! Attaches attribute name exception information
attach_attribute_name_info(exception & e,attribute_name const & name)39 BOOST_LOG_API void attach_attribute_name_info(exception& e, attribute_name const& name)
40 {
41 e << attribute_name_info(name);
42 }
43
44 } // namespace aux
45
bad_alloc(const char * descr)46 bad_alloc::bad_alloc(const char* descr) :
47 m_message(descr)
48 {
49 }
50
bad_alloc(std::string const & descr)51 bad_alloc::bad_alloc(std::string const& descr) :
52 m_message(descr)
53 {
54 }
55
~bad_alloc()56 bad_alloc::~bad_alloc() throw()
57 {
58 }
59
what() const60 const char* bad_alloc::what() const throw()
61 {
62 return m_message.c_str();
63 }
64
throw_(const char * file,std::size_t line,const char * descr)65 void bad_alloc::throw_(const char* file, std::size_t line, const char* descr)
66 {
67 boost::throw_exception(boost::enable_error_info(bad_alloc(descr))
68 << boost::throw_file(file)
69 << boost::throw_line(line)
70 );
71 }
72
throw_(const char * file,std::size_t line,std::string const & descr)73 void bad_alloc::throw_(const char* file, std::size_t line, std::string const& descr)
74 {
75 boost::throw_exception(boost::enable_error_info(bad_alloc(descr))
76 << boost::throw_file(file)
77 << boost::throw_line(line)
78 );
79 }
80
capacity_limit_reached(const char * descr)81 capacity_limit_reached::capacity_limit_reached(const char* descr) :
82 bad_alloc(descr)
83 {
84 }
85
capacity_limit_reached(std::string const & descr)86 capacity_limit_reached::capacity_limit_reached(std::string const& descr) :
87 bad_alloc(descr)
88 {
89 }
90
~capacity_limit_reached()91 capacity_limit_reached::~capacity_limit_reached() throw()
92 {
93 }
94
throw_(const char * file,std::size_t line,const char * descr)95 void capacity_limit_reached::throw_(const char* file, std::size_t line, const char* descr)
96 {
97 boost::throw_exception(boost::enable_error_info(capacity_limit_reached(descr))
98 << boost::throw_file(file)
99 << boost::throw_line(line)
100 );
101 }
102
throw_(const char * file,std::size_t line,std::string const & descr)103 void capacity_limit_reached::throw_(const char* file, std::size_t line, std::string const& descr)
104 {
105 boost::throw_exception(boost::enable_error_info(capacity_limit_reached(descr))
106 << boost::throw_file(file)
107 << boost::throw_line(line)
108 );
109 }
110
runtime_error(std::string const & descr)111 runtime_error::runtime_error(std::string const& descr) :
112 std::runtime_error(descr)
113 {
114 }
115
~runtime_error()116 runtime_error::~runtime_error() throw()
117 {
118 }
119
missing_value()120 missing_value::missing_value() :
121 runtime_error("Requested value not found")
122 {
123 }
124
missing_value(std::string const & descr)125 missing_value::missing_value(std::string const& descr) :
126 runtime_error(descr)
127 {
128 }
129
~missing_value()130 missing_value::~missing_value() throw()
131 {
132 }
133
throw_(const char * file,std::size_t line)134 void missing_value::throw_(const char* file, std::size_t line)
135 {
136 boost::throw_exception(boost::enable_error_info(missing_value())
137 << boost::throw_file(file)
138 << boost::throw_line(line)
139 );
140 }
141
throw_(const char * file,std::size_t line,const char * descr)142 void missing_value::throw_(const char* file, std::size_t line, const char* descr)
143 {
144 boost::throw_exception(boost::enable_error_info(missing_value(descr))
145 << boost::throw_file(file)
146 << boost::throw_line(line)
147 );
148 }
149
throw_(const char * file,std::size_t line,std::string const & descr)150 void missing_value::throw_(const char* file, std::size_t line, std::string const& descr)
151 {
152 boost::throw_exception(boost::enable_error_info(missing_value(descr))
153 << boost::throw_file(file)
154 << boost::throw_line(line)
155 );
156 }
157
throw_(const char * file,std::size_t line,const char * descr,attribute_name const & name)158 void missing_value::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name)
159 {
160 boost::throw_exception(boost::enable_error_info(missing_value(descr))
161 << boost::throw_file(file)
162 << boost::throw_line(line)
163 << attribute_name_info(name)
164 );
165 }
166
throw_(const char * file,std::size_t line,std::string const & descr,attribute_name const & name)167 void missing_value::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name)
168 {
169 boost::throw_exception(boost::enable_error_info(missing_value(descr))
170 << boost::throw_file(file)
171 << boost::throw_line(line)
172 << attribute_name_info(name)
173 );
174 }
175
invalid_type()176 invalid_type::invalid_type() :
177 runtime_error("Requested value has invalid type")
178 {
179 }
180
invalid_type(std::string const & descr)181 invalid_type::invalid_type(std::string const& descr) :
182 runtime_error(descr)
183 {
184 }
185
~invalid_type()186 invalid_type::~invalid_type() throw()
187 {
188 }
189
throw_(const char * file,std::size_t line)190 void invalid_type::throw_(const char* file, std::size_t line)
191 {
192 boost::throw_exception(boost::enable_error_info(invalid_type())
193 << boost::throw_file(file)
194 << boost::throw_line(line)
195 );
196 }
197
throw_(const char * file,std::size_t line,const char * descr)198 void invalid_type::throw_(const char* file, std::size_t line, const char* descr)
199 {
200 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
201 << boost::throw_file(file)
202 << boost::throw_line(line)
203 );
204 }
205
throw_(const char * file,std::size_t line,std::string const & descr)206 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr)
207 {
208 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
209 << boost::throw_file(file)
210 << boost::throw_line(line)
211 );
212 }
213
throw_(const char * file,std::size_t line,const char * descr,attribute_name const & name)214 void invalid_type::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name)
215 {
216 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
217 << boost::throw_file(file)
218 << boost::throw_line(line)
219 << attribute_name_info(name)
220 );
221 }
222
throw_(const char * file,std::size_t line,std::string const & descr,attribute_name const & name)223 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name)
224 {
225 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
226 << boost::throw_file(file)
227 << boost::throw_line(line)
228 << attribute_name_info(name)
229 );
230 }
231
throw_(const char * file,std::size_t line,const char * descr,typeindex::type_index const & type)232 void invalid_type::throw_(const char* file, std::size_t line, const char* descr, typeindex::type_index const& type)
233 {
234 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
235 << boost::throw_file(file)
236 << boost::throw_line(line)
237 << type_info_info(type)
238 );
239 }
240
throw_(const char * file,std::size_t line,std::string const & descr,typeindex::type_index const & type)241 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr, typeindex::type_index const& type)
242 {
243 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
244 << boost::throw_file(file)
245 << boost::throw_line(line)
246 << type_info_info(type)
247 );
248 }
249
throw_(const char * file,std::size_t line,const char * descr,attribute_name const & name,typeindex::type_index const & type)250 void invalid_type::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name, typeindex::type_index const& type)
251 {
252 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
253 << boost::throw_file(file)
254 << boost::throw_line(line)
255 << attribute_name_info(name)
256 << type_info_info(type)
257 );
258 }
259
throw_(const char * file,std::size_t line,std::string const & descr,attribute_name const & name,typeindex::type_index const & type)260 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name, typeindex::type_index const& type)
261 {
262 boost::throw_exception(boost::enable_error_info(invalid_type(descr))
263 << boost::throw_file(file)
264 << boost::throw_line(line)
265 << attribute_name_info(name)
266 << type_info_info(type)
267 );
268 }
269
invalid_value()270 invalid_value::invalid_value() :
271 runtime_error("The value is invalid")
272 {
273 }
274
invalid_value(std::string const & descr)275 invalid_value::invalid_value(std::string const& descr) :
276 runtime_error(descr)
277 {
278 }
279
~invalid_value()280 invalid_value::~invalid_value() throw()
281 {
282 }
283
throw_(const char * file,std::size_t line)284 void invalid_value::throw_(const char* file, std::size_t line)
285 {
286 boost::throw_exception(boost::enable_error_info(invalid_value())
287 << boost::throw_file(file)
288 << boost::throw_line(line)
289 );
290 }
291
throw_(const char * file,std::size_t line,const char * descr)292 void invalid_value::throw_(const char* file, std::size_t line, const char* descr)
293 {
294 boost::throw_exception(boost::enable_error_info(invalid_value(descr))
295 << boost::throw_file(file)
296 << boost::throw_line(line)
297 );
298 }
299
throw_(const char * file,std::size_t line,std::string const & descr)300 void invalid_value::throw_(const char* file, std::size_t line, std::string const& descr)
301 {
302 boost::throw_exception(boost::enable_error_info(invalid_value(descr))
303 << boost::throw_file(file)
304 << boost::throw_line(line)
305 );
306 }
307
parse_error()308 parse_error::parse_error() :
309 runtime_error("Failed to parse content")
310 {
311 }
312
parse_error(std::string const & descr)313 parse_error::parse_error(std::string const& descr) :
314 runtime_error(descr)
315 {
316 }
317
~parse_error()318 parse_error::~parse_error() throw()
319 {
320 }
321
throw_(const char * file,std::size_t line)322 void parse_error::throw_(const char* file, std::size_t line)
323 {
324 boost::throw_exception(boost::enable_error_info(parse_error())
325 << boost::throw_file(file)
326 << boost::throw_line(line)
327 );
328 }
329
throw_(const char * file,std::size_t line,const char * descr)330 void parse_error::throw_(const char* file, std::size_t line, const char* descr)
331 {
332 boost::throw_exception(boost::enable_error_info(parse_error(descr))
333 << boost::throw_file(file)
334 << boost::throw_line(line)
335 );
336 }
337
throw_(const char * file,std::size_t line,std::string const & descr)338 void parse_error::throw_(const char* file, std::size_t line, std::string const& descr)
339 {
340 boost::throw_exception(boost::enable_error_info(parse_error(descr))
341 << boost::throw_file(file)
342 << boost::throw_line(line)
343 );
344 }
345
throw_(const char * file,std::size_t line,const char * descr,std::size_t content_line)346 void parse_error::throw_(const char* file, std::size_t line, const char* descr, std::size_t content_line)
347 {
348 boost::throw_exception(boost::enable_error_info(parse_error(descr))
349 << boost::throw_file(file)
350 << boost::throw_line(line)
351 << boost::errinfo_at_line(content_line)
352 );
353 }
354
throw_(const char * file,std::size_t line,std::string const & descr,std::size_t content_line)355 void parse_error::throw_(const char* file, std::size_t line, std::string const& descr, std::size_t content_line)
356 {
357 boost::throw_exception(boost::enable_error_info(parse_error(descr))
358 << boost::throw_file(file)
359 << boost::throw_line(line)
360 << boost::errinfo_at_line(content_line)
361 );
362 }
363
throw_(const char * file,std::size_t line,const char * descr,attribute_name const & name)364 void parse_error::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name)
365 {
366 boost::throw_exception(boost::enable_error_info(parse_error(descr))
367 << boost::throw_file(file)
368 << boost::throw_line(line)
369 << attribute_name_info(name)
370 );
371 }
372
throw_(const char * file,std::size_t line,std::string const & descr,attribute_name const & name)373 void parse_error::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name)
374 {
375 boost::throw_exception(boost::enable_error_info(parse_error(descr))
376 << boost::throw_file(file)
377 << boost::throw_line(line)
378 << attribute_name_info(name)
379 );
380 }
381
conversion_error()382 conversion_error::conversion_error() :
383 runtime_error("Failed to perform conversion")
384 {
385 }
386
conversion_error(std::string const & descr)387 conversion_error::conversion_error(std::string const& descr) :
388 runtime_error(descr)
389 {
390 }
391
~conversion_error()392 conversion_error::~conversion_error() throw()
393 {
394 }
395
throw_(const char * file,std::size_t line)396 void conversion_error::throw_(const char* file, std::size_t line)
397 {
398 boost::throw_exception(boost::enable_error_info(conversion_error())
399 << boost::throw_file(file)
400 << boost::throw_line(line)
401 );
402 }
403
throw_(const char * file,std::size_t line,const char * descr)404 void conversion_error::throw_(const char* file, std::size_t line, const char* descr)
405 {
406 boost::throw_exception(boost::enable_error_info(conversion_error(descr))
407 << boost::throw_file(file)
408 << boost::throw_line(line)
409 );
410 }
411
throw_(const char * file,std::size_t line,std::string const & descr)412 void conversion_error::throw_(const char* file, std::size_t line, std::string const& descr)
413 {
414 boost::throw_exception(boost::enable_error_info(conversion_error(descr))
415 << boost::throw_file(file)
416 << boost::throw_line(line)
417 );
418 }
419
system_error(boost::system::error_code code,std::string const & descr)420 system_error::system_error(boost::system::error_code code, std::string const& descr) :
421 boost::system::system_error(code, descr)
422 {
423 }
424
~system_error()425 system_error::~system_error() throw()
426 {
427 }
428
throw_(const char * file,std::size_t line,const char * descr,int system_error_code)429 void system_error::throw_(const char* file, std::size_t line, const char* descr, int system_error_code)
430 {
431 boost::throw_exception(boost::enable_error_info(system_error(boost::system::error_code(system_error_code, boost::system::system_category()), descr))
432 << boost::throw_file(file)
433 << boost::throw_line(line)
434 );
435 }
436
throw_(const char * file,std::size_t line,std::string const & descr,int system_error_code)437 void system_error::throw_(const char* file, std::size_t line, std::string const& descr, int system_error_code)
438 {
439 boost::throw_exception(boost::enable_error_info(system_error(boost::system::error_code(system_error_code, boost::system::system_category()), descr))
440 << boost::throw_file(file)
441 << boost::throw_line(line)
442 );
443 }
444
throw_(const char * file,std::size_t line,const char * descr,boost::system::error_code code)445 void system_error::throw_(const char* file, std::size_t line, const char* descr, boost::system::error_code code)
446 {
447 boost::throw_exception(boost::enable_error_info(system_error(code, descr))
448 << boost::throw_file(file)
449 << boost::throw_line(line)
450 );
451 }
452
throw_(const char * file,std::size_t line,std::string const & descr,boost::system::error_code code)453 void system_error::throw_(const char* file, std::size_t line, std::string const& descr, boost::system::error_code code)
454 {
455 boost::throw_exception(boost::enable_error_info(system_error(code, descr))
456 << boost::throw_file(file)
457 << boost::throw_line(line)
458 );
459 }
460
logic_error(std::string const & descr)461 logic_error::logic_error(std::string const& descr) :
462 std::logic_error(descr)
463 {
464 }
465
~logic_error()466 logic_error::~logic_error() throw()
467 {
468 }
469
throw_(const char * file,std::size_t line,const char * descr)470 void logic_error::throw_(const char* file, std::size_t line, const char* descr)
471 {
472 boost::throw_exception(boost::enable_error_info(logic_error(descr))
473 << boost::throw_file(file)
474 << boost::throw_line(line)
475 );
476 }
477
throw_(const char * file,std::size_t line,std::string const & descr)478 void logic_error::throw_(const char* file, std::size_t line, std::string const& descr)
479 {
480 boost::throw_exception(boost::enable_error_info(logic_error(descr))
481 << boost::throw_file(file)
482 << boost::throw_line(line)
483 );
484 }
485
odr_violation()486 odr_violation::odr_violation() :
487 logic_error("ODR violation detected")
488 {
489 }
490
odr_violation(std::string const & descr)491 odr_violation::odr_violation(std::string const& descr) :
492 logic_error(descr)
493 {
494 }
495
~odr_violation()496 odr_violation::~odr_violation() throw()
497 {
498 }
499
throw_(const char * file,std::size_t line)500 void odr_violation::throw_(const char* file, std::size_t line)
501 {
502 boost::throw_exception(boost::enable_error_info(odr_violation())
503 << boost::throw_file(file)
504 << boost::throw_line(line)
505 );
506 }
507
throw_(const char * file,std::size_t line,const char * descr)508 void odr_violation::throw_(const char* file, std::size_t line, const char* descr)
509 {
510 boost::throw_exception(boost::enable_error_info(odr_violation(descr))
511 << boost::throw_file(file)
512 << boost::throw_line(line)
513 );
514 }
515
throw_(const char * file,std::size_t line,std::string const & descr)516 void odr_violation::throw_(const char* file, std::size_t line, std::string const& descr)
517 {
518 boost::throw_exception(boost::enable_error_info(odr_violation(descr))
519 << boost::throw_file(file)
520 << boost::throw_line(line)
521 );
522 }
523
unexpected_call()524 unexpected_call::unexpected_call() :
525 logic_error("Invalid call sequence")
526 {
527 }
528
unexpected_call(std::string const & descr)529 unexpected_call::unexpected_call(std::string const& descr) :
530 logic_error(descr)
531 {
532 }
533
~unexpected_call()534 unexpected_call::~unexpected_call() throw()
535 {
536 }
537
throw_(const char * file,std::size_t line)538 void unexpected_call::throw_(const char* file, std::size_t line)
539 {
540 boost::throw_exception(boost::enable_error_info(unexpected_call())
541 << boost::throw_file(file)
542 << boost::throw_line(line)
543 );
544 }
545
throw_(const char * file,std::size_t line,const char * descr)546 void unexpected_call::throw_(const char* file, std::size_t line, const char* descr)
547 {
548 boost::throw_exception(boost::enable_error_info(unexpected_call(descr))
549 << boost::throw_file(file)
550 << boost::throw_line(line)
551 );
552 }
553
throw_(const char * file,std::size_t line,std::string const & descr)554 void unexpected_call::throw_(const char* file, std::size_t line, std::string const& descr)
555 {
556 boost::throw_exception(boost::enable_error_info(unexpected_call(descr))
557 << boost::throw_file(file)
558 << boost::throw_line(line)
559 );
560 }
561
setup_error()562 setup_error::setup_error() :
563 logic_error("The library is not initialized properly")
564 {
565 }
566
setup_error(std::string const & descr)567 setup_error::setup_error(std::string const& descr) :
568 logic_error(descr)
569 {
570 }
571
~setup_error()572 setup_error::~setup_error() throw()
573 {
574 }
575
throw_(const char * file,std::size_t line)576 void setup_error::throw_(const char* file, std::size_t line)
577 {
578 boost::throw_exception(boost::enable_error_info(setup_error())
579 << boost::throw_file(file)
580 << boost::throw_line(line)
581 );
582 }
583
throw_(const char * file,std::size_t line,const char * descr)584 void setup_error::throw_(const char* file, std::size_t line, const char* descr)
585 {
586 boost::throw_exception(boost::enable_error_info(setup_error(descr))
587 << boost::throw_file(file)
588 << boost::throw_line(line)
589 );
590 }
591
throw_(const char * file,std::size_t line,std::string const & descr)592 void setup_error::throw_(const char* file, std::size_t line, std::string const& descr)
593 {
594 boost::throw_exception(boost::enable_error_info(setup_error(descr))
595 << boost::throw_file(file)
596 << boost::throw_line(line)
597 );
598 }
599
limitation_error()600 limitation_error::limitation_error() :
601 logic_error("Boost.Log library limit reached")
602 {
603 }
604
limitation_error(std::string const & descr)605 limitation_error::limitation_error(std::string const& descr) :
606 logic_error(descr)
607 {
608 }
609
~limitation_error()610 limitation_error::~limitation_error() throw()
611 {
612 }
613
throw_(const char * file,std::size_t line)614 void limitation_error::throw_(const char* file, std::size_t line)
615 {
616 boost::throw_exception(boost::enable_error_info(limitation_error())
617 << boost::throw_file(file)
618 << boost::throw_line(line)
619 );
620 }
621
throw_(const char * file,std::size_t line,const char * descr)622 void limitation_error::throw_(const char* file, std::size_t line, const char* descr)
623 {
624 boost::throw_exception(boost::enable_error_info(limitation_error(descr))
625 << boost::throw_file(file)
626 << boost::throw_line(line)
627 );
628 }
629
throw_(const char * file,std::size_t line,std::string const & descr)630 void limitation_error::throw_(const char* file, std::size_t line, std::string const& descr)
631 {
632 boost::throw_exception(boost::enable_error_info(limitation_error(descr))
633 << boost::throw_file(file)
634 << boost::throw_line(line)
635 );
636 }
637
638 BOOST_LOG_CLOSE_NAMESPACE // namespace log
639
640 } // namespace boost
641
642 #ifdef _MSC_VER
643 #pragma warning(pop)
644 #endif
645
646 #include <boost/log/detail/footer.hpp>
647