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 |
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 | |
46 | bad_alloc::bad_alloc(const char* descr) : |
47 | m_message(descr) |
48 | { |
49 | } |
50 | |
51 | bad_alloc::bad_alloc(std::string const& descr) : |
52 | m_message(descr) |
53 | { |
54 | } |
55 | |
56 | bad_alloc::~bad_alloc() throw() |
57 | { |
58 | } |
59 | |
60 | const char* bad_alloc::what() const throw() |
61 | { |
62 | return m_message.c_str(); |
63 | } |
64 | |
65 | void bad_alloc::throw_(const char* file, std::size_t line, const char* descr) |
66 | { |
67 | boost::throw_exception(e: boost::enable_error_info(x: bad_alloc(descr)) |
68 | << boost::throw_file(file) |
69 | << boost::throw_line(line) |
70 | ); |
71 | } |
72 | |
73 | void bad_alloc::throw_(const char* file, std::size_t line, std::string const& descr) |
74 | { |
75 | boost::throw_exception(e: boost::enable_error_info(x: bad_alloc(descr)) |
76 | << boost::throw_file(file) |
77 | << boost::throw_line(line) |
78 | ); |
79 | } |
80 | |
81 | capacity_limit_reached::capacity_limit_reached(const char* descr) : |
82 | bad_alloc(descr) |
83 | { |
84 | } |
85 | |
86 | capacity_limit_reached::capacity_limit_reached(std::string const& descr) : |
87 | bad_alloc(descr) |
88 | { |
89 | } |
90 | |
91 | capacity_limit_reached::~capacity_limit_reached() throw() |
92 | { |
93 | } |
94 | |
95 | void capacity_limit_reached::throw_(const char* file, std::size_t line, const char* descr) |
96 | { |
97 | boost::throw_exception(e: boost::enable_error_info(x: capacity_limit_reached(descr)) |
98 | << boost::throw_file(file) |
99 | << boost::throw_line(line) |
100 | ); |
101 | } |
102 | |
103 | void capacity_limit_reached::throw_(const char* file, std::size_t line, std::string const& descr) |
104 | { |
105 | boost::throw_exception(e: boost::enable_error_info(x: capacity_limit_reached(descr)) |
106 | << boost::throw_file(file) |
107 | << boost::throw_line(line) |
108 | ); |
109 | } |
110 | |
111 | runtime_error::runtime_error(std::string const& descr) : |
112 | std::runtime_error(descr) |
113 | { |
114 | } |
115 | |
116 | runtime_error::~runtime_error() throw() |
117 | { |
118 | } |
119 | |
120 | missing_value::missing_value() : |
121 | runtime_error("Requested value not found" ) |
122 | { |
123 | } |
124 | |
125 | missing_value::missing_value(std::string const& descr) : |
126 | runtime_error(descr) |
127 | { |
128 | } |
129 | |
130 | missing_value::~missing_value() throw() |
131 | { |
132 | } |
133 | |
134 | void missing_value::throw_(const char* file, std::size_t line) |
135 | { |
136 | boost::throw_exception(e: boost::enable_error_info(x: missing_value()) |
137 | << boost::throw_file(file) |
138 | << boost::throw_line(line) |
139 | ); |
140 | } |
141 | |
142 | void missing_value::throw_(const char* file, std::size_t line, const char* descr) |
143 | { |
144 | boost::throw_exception(e: boost::enable_error_info(x: missing_value(descr)) |
145 | << boost::throw_file(file) |
146 | << boost::throw_line(line) |
147 | ); |
148 | } |
149 | |
150 | void missing_value::throw_(const char* file, std::size_t line, std::string const& descr) |
151 | { |
152 | boost::throw_exception(e: boost::enable_error_info(x: missing_value(descr)) |
153 | << boost::throw_file(file) |
154 | << boost::throw_line(line) |
155 | ); |
156 | } |
157 | |
158 | void missing_value::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name) |
159 | { |
160 | boost::throw_exception(e: boost::enable_error_info(x: missing_value(descr)) |
161 | << boost::throw_file(file) |
162 | << boost::throw_line(line) |
163 | << attribute_name_info(name) |
164 | ); |
165 | } |
166 | |
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(e: boost::enable_error_info(x: missing_value(descr)) |
170 | << boost::throw_file(file) |
171 | << boost::throw_line(line) |
172 | << attribute_name_info(name) |
173 | ); |
174 | } |
175 | |
176 | invalid_type::invalid_type() : |
177 | runtime_error("Requested value has invalid type" ) |
178 | { |
179 | } |
180 | |
181 | invalid_type::invalid_type(std::string const& descr) : |
182 | runtime_error(descr) |
183 | { |
184 | } |
185 | |
186 | invalid_type::~invalid_type() throw() |
187 | { |
188 | } |
189 | |
190 | void invalid_type::throw_(const char* file, std::size_t line) |
191 | { |
192 | boost::throw_exception(e: boost::enable_error_info(x: invalid_type()) |
193 | << boost::throw_file(file) |
194 | << boost::throw_line(line) |
195 | ); |
196 | } |
197 | |
198 | void invalid_type::throw_(const char* file, std::size_t line, const char* descr) |
199 | { |
200 | boost::throw_exception(e: boost::enable_error_info(x: invalid_type(descr)) |
201 | << boost::throw_file(file) |
202 | << boost::throw_line(line) |
203 | ); |
204 | } |
205 | |
206 | void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr) |
207 | { |
208 | boost::throw_exception(e: boost::enable_error_info(x: invalid_type(descr)) |
209 | << boost::throw_file(file) |
210 | << boost::throw_line(line) |
211 | ); |
212 | } |
213 | |
214 | void invalid_type::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name) |
215 | { |
216 | boost::throw_exception(e: boost::enable_error_info(x: invalid_type(descr)) |
217 | << boost::throw_file(file) |
218 | << boost::throw_line(line) |
219 | << attribute_name_info(name) |
220 | ); |
221 | } |
222 | |
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(e: boost::enable_error_info(x: invalid_type(descr)) |
226 | << boost::throw_file(file) |
227 | << boost::throw_line(line) |
228 | << attribute_name_info(name) |
229 | ); |
230 | } |
231 | |
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(e: boost::enable_error_info(x: invalid_type(descr)) |
235 | << boost::throw_file(file) |
236 | << boost::throw_line(line) |
237 | << type_info_info(type) |
238 | ); |
239 | } |
240 | |
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(e: boost::enable_error_info(x: invalid_type(descr)) |
244 | << boost::throw_file(file) |
245 | << boost::throw_line(line) |
246 | << type_info_info(type) |
247 | ); |
248 | } |
249 | |
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(e: boost::enable_error_info(x: 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 | |
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(e: boost::enable_error_info(x: 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 | |
270 | invalid_value::invalid_value() : |
271 | runtime_error("The value is invalid" ) |
272 | { |
273 | } |
274 | |
275 | invalid_value::invalid_value(std::string const& descr) : |
276 | runtime_error(descr) |
277 | { |
278 | } |
279 | |
280 | invalid_value::~invalid_value() throw() |
281 | { |
282 | } |
283 | |
284 | void invalid_value::throw_(const char* file, std::size_t line) |
285 | { |
286 | boost::throw_exception(e: boost::enable_error_info(x: invalid_value()) |
287 | << boost::throw_file(file) |
288 | << boost::throw_line(line) |
289 | ); |
290 | } |
291 | |
292 | void invalid_value::throw_(const char* file, std::size_t line, const char* descr) |
293 | { |
294 | boost::throw_exception(e: boost::enable_error_info(x: invalid_value(descr)) |
295 | << boost::throw_file(file) |
296 | << boost::throw_line(line) |
297 | ); |
298 | } |
299 | |
300 | void invalid_value::throw_(const char* file, std::size_t line, std::string const& descr) |
301 | { |
302 | boost::throw_exception(e: boost::enable_error_info(x: invalid_value(descr)) |
303 | << boost::throw_file(file) |
304 | << boost::throw_line(line) |
305 | ); |
306 | } |
307 | |
308 | parse_error::parse_error() : |
309 | runtime_error("Failed to parse content" ) |
310 | { |
311 | } |
312 | |
313 | parse_error::parse_error(std::string const& descr) : |
314 | runtime_error(descr) |
315 | { |
316 | } |
317 | |
318 | parse_error::~parse_error() throw() |
319 | { |
320 | } |
321 | |
322 | void parse_error::throw_(const char* file, std::size_t line) |
323 | { |
324 | boost::throw_exception(e: boost::enable_error_info(x: parse_error()) |
325 | << boost::throw_file(file) |
326 | << boost::throw_line(line) |
327 | ); |
328 | } |
329 | |
330 | void parse_error::throw_(const char* file, std::size_t line, const char* descr) |
331 | { |
332 | boost::throw_exception(e: boost::enable_error_info(x: parse_error(descr)) |
333 | << boost::throw_file(file) |
334 | << boost::throw_line(line) |
335 | ); |
336 | } |
337 | |
338 | void parse_error::throw_(const char* file, std::size_t line, std::string const& descr) |
339 | { |
340 | boost::throw_exception(e: boost::enable_error_info(x: parse_error(descr)) |
341 | << boost::throw_file(file) |
342 | << boost::throw_line(line) |
343 | ); |
344 | } |
345 | |
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(e: boost::enable_error_info(x: parse_error(descr)) |
349 | << boost::throw_file(file) |
350 | << boost::throw_line(line) |
351 | << boost::errinfo_at_line(content_line) |
352 | ); |
353 | } |
354 | |
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(e: boost::enable_error_info(x: parse_error(descr)) |
358 | << boost::throw_file(file) |
359 | << boost::throw_line(line) |
360 | << boost::errinfo_at_line(content_line) |
361 | ); |
362 | } |
363 | |
364 | void parse_error::throw_(const char* file, std::size_t line, const char* descr, attribute_name const& name) |
365 | { |
366 | boost::throw_exception(e: boost::enable_error_info(x: parse_error(descr)) |
367 | << boost::throw_file(file) |
368 | << boost::throw_line(line) |
369 | << attribute_name_info(name) |
370 | ); |
371 | } |
372 | |
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(e: boost::enable_error_info(x: parse_error(descr)) |
376 | << boost::throw_file(file) |
377 | << boost::throw_line(line) |
378 | << attribute_name_info(name) |
379 | ); |
380 | } |
381 | |
382 | conversion_error::conversion_error() : |
383 | runtime_error("Failed to perform conversion" ) |
384 | { |
385 | } |
386 | |
387 | conversion_error::conversion_error(std::string const& descr) : |
388 | runtime_error(descr) |
389 | { |
390 | } |
391 | |
392 | conversion_error::~conversion_error() throw() |
393 | { |
394 | } |
395 | |
396 | void conversion_error::throw_(const char* file, std::size_t line) |
397 | { |
398 | boost::throw_exception(e: boost::enable_error_info(x: conversion_error()) |
399 | << boost::throw_file(file) |
400 | << boost::throw_line(line) |
401 | ); |
402 | } |
403 | |
404 | void conversion_error::throw_(const char* file, std::size_t line, const char* descr) |
405 | { |
406 | boost::throw_exception(e: boost::enable_error_info(x: conversion_error(descr)) |
407 | << boost::throw_file(file) |
408 | << boost::throw_line(line) |
409 | ); |
410 | } |
411 | |
412 | void conversion_error::throw_(const char* file, std::size_t line, std::string const& descr) |
413 | { |
414 | boost::throw_exception(e: boost::enable_error_info(x: conversion_error(descr)) |
415 | << boost::throw_file(file) |
416 | << boost::throw_line(line) |
417 | ); |
418 | } |
419 | |
420 | system_error::system_error(boost::system::error_code code, std::string const& descr) : |
421 | boost::system::system_error(code, descr) |
422 | { |
423 | } |
424 | |
425 | system_error::~system_error() throw() |
426 | { |
427 | } |
428 | |
429 | void system_error::throw_(const char* file, std::size_t line, const char* descr, int system_error_code) |
430 | { |
431 | boost::throw_exception(e: boost::enable_error_info(x: 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 | |
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(e: boost::enable_error_info(x: 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 | |
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(e: boost::enable_error_info(x: system_error(code, descr)) |
448 | << boost::throw_file(file) |
449 | << boost::throw_line(line) |
450 | ); |
451 | } |
452 | |
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(e: boost::enable_error_info(x: system_error(code, descr)) |
456 | << boost::throw_file(file) |
457 | << boost::throw_line(line) |
458 | ); |
459 | } |
460 | |
461 | logic_error::logic_error(std::string const& descr) : |
462 | std::logic_error(descr) |
463 | { |
464 | } |
465 | |
466 | logic_error::~logic_error() throw() |
467 | { |
468 | } |
469 | |
470 | void logic_error::throw_(const char* file, std::size_t line, const char* descr) |
471 | { |
472 | boost::throw_exception(e: boost::enable_error_info(x: logic_error(descr)) |
473 | << boost::throw_file(file) |
474 | << boost::throw_line(line) |
475 | ); |
476 | } |
477 | |
478 | void logic_error::throw_(const char* file, std::size_t line, std::string const& descr) |
479 | { |
480 | boost::throw_exception(e: boost::enable_error_info(x: logic_error(descr)) |
481 | << boost::throw_file(file) |
482 | << boost::throw_line(line) |
483 | ); |
484 | } |
485 | |
486 | odr_violation::odr_violation() : |
487 | logic_error("ODR violation detected" ) |
488 | { |
489 | } |
490 | |
491 | odr_violation::odr_violation(std::string const& descr) : |
492 | logic_error(descr) |
493 | { |
494 | } |
495 | |
496 | odr_violation::~odr_violation() throw() |
497 | { |
498 | } |
499 | |
500 | void odr_violation::throw_(const char* file, std::size_t line) |
501 | { |
502 | boost::throw_exception(e: boost::enable_error_info(x: odr_violation()) |
503 | << boost::throw_file(file) |
504 | << boost::throw_line(line) |
505 | ); |
506 | } |
507 | |
508 | void odr_violation::throw_(const char* file, std::size_t line, const char* descr) |
509 | { |
510 | boost::throw_exception(e: boost::enable_error_info(x: odr_violation(descr)) |
511 | << boost::throw_file(file) |
512 | << boost::throw_line(line) |
513 | ); |
514 | } |
515 | |
516 | void odr_violation::throw_(const char* file, std::size_t line, std::string const& descr) |
517 | { |
518 | boost::throw_exception(e: boost::enable_error_info(x: odr_violation(descr)) |
519 | << boost::throw_file(file) |
520 | << boost::throw_line(line) |
521 | ); |
522 | } |
523 | |
524 | unexpected_call::unexpected_call() : |
525 | logic_error("Invalid call sequence" ) |
526 | { |
527 | } |
528 | |
529 | unexpected_call::unexpected_call(std::string const& descr) : |
530 | logic_error(descr) |
531 | { |
532 | } |
533 | |
534 | unexpected_call::~unexpected_call() throw() |
535 | { |
536 | } |
537 | |
538 | void unexpected_call::throw_(const char* file, std::size_t line) |
539 | { |
540 | boost::throw_exception(e: boost::enable_error_info(x: unexpected_call()) |
541 | << boost::throw_file(file) |
542 | << boost::throw_line(line) |
543 | ); |
544 | } |
545 | |
546 | void unexpected_call::throw_(const char* file, std::size_t line, const char* descr) |
547 | { |
548 | boost::throw_exception(e: boost::enable_error_info(x: unexpected_call(descr)) |
549 | << boost::throw_file(file) |
550 | << boost::throw_line(line) |
551 | ); |
552 | } |
553 | |
554 | void unexpected_call::throw_(const char* file, std::size_t line, std::string const& descr) |
555 | { |
556 | boost::throw_exception(e: boost::enable_error_info(x: unexpected_call(descr)) |
557 | << boost::throw_file(file) |
558 | << boost::throw_line(line) |
559 | ); |
560 | } |
561 | |
562 | setup_error::setup_error() : |
563 | logic_error("The library is not initialized properly" ) |
564 | { |
565 | } |
566 | |
567 | setup_error::setup_error(std::string const& descr) : |
568 | logic_error(descr) |
569 | { |
570 | } |
571 | |
572 | setup_error::~setup_error() throw() |
573 | { |
574 | } |
575 | |
576 | void setup_error::throw_(const char* file, std::size_t line) |
577 | { |
578 | boost::throw_exception(e: boost::enable_error_info(x: setup_error()) |
579 | << boost::throw_file(file) |
580 | << boost::throw_line(line) |
581 | ); |
582 | } |
583 | |
584 | void setup_error::throw_(const char* file, std::size_t line, const char* descr) |
585 | { |
586 | boost::throw_exception(e: boost::enable_error_info(x: setup_error(descr)) |
587 | << boost::throw_file(file) |
588 | << boost::throw_line(line) |
589 | ); |
590 | } |
591 | |
592 | void setup_error::throw_(const char* file, std::size_t line, std::string const& descr) |
593 | { |
594 | boost::throw_exception(e: boost::enable_error_info(x: setup_error(descr)) |
595 | << boost::throw_file(file) |
596 | << boost::throw_line(line) |
597 | ); |
598 | } |
599 | |
600 | limitation_error::limitation_error() : |
601 | logic_error("Boost.Log library limit reached" ) |
602 | { |
603 | } |
604 | |
605 | limitation_error::limitation_error(std::string const& descr) : |
606 | logic_error(descr) |
607 | { |
608 | } |
609 | |
610 | limitation_error::~limitation_error() throw() |
611 | { |
612 | } |
613 | |
614 | void limitation_error::throw_(const char* file, std::size_t line) |
615 | { |
616 | boost::throw_exception(e: boost::enable_error_info(x: limitation_error()) |
617 | << boost::throw_file(file) |
618 | << boost::throw_line(line) |
619 | ); |
620 | } |
621 | |
622 | void limitation_error::throw_(const char* file, std::size_t line, const char* descr) |
623 | { |
624 | boost::throw_exception(e: boost::enable_error_info(x: limitation_error(descr)) |
625 | << boost::throw_file(file) |
626 | << boost::throw_line(line) |
627 | ); |
628 | } |
629 | |
630 | void limitation_error::throw_(const char* file, std::size_t line, std::string const& descr) |
631 | { |
632 | boost::throw_exception(e: boost::enable_error_info(x: 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 | |