Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / log / src / exceptions.cpp
1 /*
2  *          Copyright Andrey Semashev 2007 - 2014.
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/throw_exception.hpp>
17 #include <boost/exception/exception.hpp>
18 #include <boost/exception/errinfo_at_line.hpp>
19 #include <boost/exception/info.hpp>
20 #include <boost/log/exceptions.hpp>
21 #include <boost/log/support/exception.hpp>
22 #include <boost/log/detail/header.hpp>
23
24 #ifdef _MSC_VER
25 #pragma warning(push)
26 // conversion from 'size_t' to 'boost::error_info<boost::throw_line_,int>::value_type', possible loss of data
27 // No idea why line number is stored as a signed integer in the error info...
28 #pragma warning(disable: 4267)
29 #endif
30
31 namespace boost {
32
33 BOOST_LOG_OPEN_NAMESPACE
34
35 namespace aux {
36
37 //! Attaches attribute name exception information
38 BOOST_LOG_API void attach_attribute_name_info(exception& e, attribute_name const& name)
39 {
40     e << attribute_name_info(name);
41 }
42
43 } // namespace aux
44
45 runtime_error::runtime_error(std::string const& descr) :
46     std::runtime_error(descr)
47 {
48 }
49
50 runtime_error::~runtime_error() throw()
51 {
52 }
53
54 missing_value::missing_value() :
55     runtime_error("Requested value not found")
56 {
57 }
58
59 missing_value::missing_value(std::string const& descr) :
60     runtime_error(descr)
61 {
62 }
63
64 missing_value::~missing_value() throw()
65 {
66 }
67
68 void missing_value::throw_(const char* file, std::size_t line)
69 {
70     boost::throw_exception(boost::enable_error_info(missing_value())
71         << boost::throw_file(file)
72         << boost::throw_line(line)
73     );
74 }
75
76 void missing_value::throw_(const char* file, std::size_t line, std::string const& descr)
77 {
78     boost::throw_exception(boost::enable_error_info(missing_value(descr))
79         << boost::throw_file(file)
80         << boost::throw_line(line)
81     );
82 }
83
84 void missing_value::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name)
85 {
86     boost::throw_exception(boost::enable_error_info(missing_value(descr))
87         << boost::throw_file(file)
88         << boost::throw_line(line)
89         << attribute_name_info(name)
90     );
91 }
92
93 invalid_type::invalid_type() :
94     runtime_error("Requested value has invalid type")
95 {
96 }
97
98 invalid_type::invalid_type(std::string const& descr) :
99     runtime_error(descr)
100 {
101 }
102
103 invalid_type::~invalid_type() throw()
104 {
105 }
106
107 void invalid_type::throw_(const char* file, std::size_t line)
108 {
109     boost::throw_exception(boost::enable_error_info(invalid_type())
110         << boost::throw_file(file)
111         << boost::throw_line(line)
112     );
113 }
114
115 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr)
116 {
117     boost::throw_exception(boost::enable_error_info(invalid_type(descr))
118         << boost::throw_file(file)
119         << boost::throw_line(line)
120     );
121 }
122
123 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name)
124 {
125     boost::throw_exception(boost::enable_error_info(invalid_type(descr))
126         << boost::throw_file(file)
127         << boost::throw_line(line)
128         << attribute_name_info(name)
129     );
130 }
131
132 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr, type_info_wrapper const& type)
133 {
134     boost::throw_exception(boost::enable_error_info(invalid_type(descr))
135         << boost::throw_file(file)
136         << boost::throw_line(line)
137         << type_info_info(type)
138     );
139 }
140
141 void invalid_type::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name, type_info_wrapper const& type)
142 {
143     boost::throw_exception(boost::enable_error_info(invalid_type(descr))
144         << boost::throw_file(file)
145         << boost::throw_line(line)
146         << attribute_name_info(name)
147         << type_info_info(type)
148     );
149 }
150
151 invalid_value::invalid_value() :
152     runtime_error("The value is invalid")
153 {
154 }
155
156 invalid_value::invalid_value(std::string const& descr) :
157     runtime_error(descr)
158 {
159 }
160
161 invalid_value::~invalid_value() throw()
162 {
163 }
164
165 void invalid_value::throw_(const char* file, std::size_t line)
166 {
167     boost::throw_exception(boost::enable_error_info(invalid_value())
168         << boost::throw_file(file)
169         << boost::throw_line(line)
170     );
171 }
172
173 void invalid_value::throw_(const char* file, std::size_t line, std::string const& descr)
174 {
175     boost::throw_exception(boost::enable_error_info(invalid_value(descr))
176         << boost::throw_file(file)
177         << boost::throw_line(line)
178     );
179 }
180
181 parse_error::parse_error() :
182     runtime_error("Failed to parse content")
183 {
184 }
185
186 parse_error::parse_error(std::string const& descr) :
187     runtime_error(descr)
188 {
189 }
190
191 parse_error::~parse_error() throw()
192 {
193 }
194
195 void parse_error::throw_(const char* file, std::size_t line)
196 {
197     boost::throw_exception(boost::enable_error_info(parse_error())
198         << boost::throw_file(file)
199         << boost::throw_line(line)
200     );
201 }
202
203 void parse_error::throw_(const char* file, std::size_t line, std::string const& descr)
204 {
205     boost::throw_exception(boost::enable_error_info(parse_error(descr))
206         << boost::throw_file(file)
207         << boost::throw_line(line)
208     );
209 }
210
211 void parse_error::throw_(const char* file, std::size_t line, std::string const& descr, std::size_t content_line)
212 {
213     boost::throw_exception(boost::enable_error_info(parse_error(descr))
214         << boost::throw_file(file)
215         << boost::throw_line(line)
216         << boost::errinfo_at_line(content_line)
217     );
218 }
219
220 void parse_error::throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name)
221 {
222     boost::throw_exception(boost::enable_error_info(parse_error(descr))
223         << boost::throw_file(file)
224         << boost::throw_line(line)
225         << attribute_name_info(name)
226     );
227 }
228
229 conversion_error::conversion_error() :
230     runtime_error("Failed to perform conversion")
231 {
232 }
233
234 conversion_error::conversion_error(std::string const& descr) :
235     runtime_error(descr)
236 {
237 }
238
239 conversion_error::~conversion_error() throw()
240 {
241 }
242
243 void conversion_error::throw_(const char* file, std::size_t line)
244 {
245     boost::throw_exception(boost::enable_error_info(conversion_error())
246         << boost::throw_file(file)
247         << boost::throw_line(line)
248     );
249 }
250
251 void conversion_error::throw_(const char* file, std::size_t line, std::string const& descr)
252 {
253     boost::throw_exception(boost::enable_error_info(conversion_error(descr))
254         << boost::throw_file(file)
255         << boost::throw_line(line)
256     );
257 }
258
259 system_error::system_error() :
260     runtime_error("Underlying API operation failed")
261 {
262 }
263
264 system_error::system_error(std::string const& descr) :
265     runtime_error(descr)
266 {
267 }
268
269 system_error::~system_error() throw()
270 {
271 }
272
273 void system_error::throw_(const char* file, std::size_t line)
274 {
275     boost::throw_exception(boost::enable_error_info(system_error())
276         << boost::throw_file(file)
277         << boost::throw_line(line)
278     );
279 }
280
281 void system_error::throw_(const char* file, std::size_t line, std::string const& descr)
282 {
283     boost::throw_exception(boost::enable_error_info(system_error(descr))
284         << boost::throw_file(file)
285         << boost::throw_line(line)
286     );
287 }
288
289 logic_error::logic_error(std::string const& descr) :
290     std::logic_error(descr)
291 {
292 }
293
294 logic_error::~logic_error() throw()
295 {
296 }
297
298 odr_violation::odr_violation() :
299     logic_error("ODR violation detected")
300 {
301 }
302
303 odr_violation::odr_violation(std::string const& descr) :
304     logic_error(descr)
305 {
306 }
307
308 odr_violation::~odr_violation() throw()
309 {
310 }
311
312 void odr_violation::throw_(const char* file, std::size_t line)
313 {
314     boost::throw_exception(boost::enable_error_info(odr_violation())
315         << boost::throw_file(file)
316         << boost::throw_line(line)
317     );
318 }
319
320 void odr_violation::throw_(const char* file, std::size_t line, std::string const& descr)
321 {
322     boost::throw_exception(boost::enable_error_info(odr_violation(descr))
323         << boost::throw_file(file)
324         << boost::throw_line(line)
325     );
326 }
327
328 unexpected_call::unexpected_call() :
329     logic_error("Invalid call sequence")
330 {
331 }
332
333 unexpected_call::unexpected_call(std::string const& descr) :
334     logic_error(descr)
335 {
336 }
337
338 unexpected_call::~unexpected_call() throw()
339 {
340 }
341
342 void unexpected_call::throw_(const char* file, std::size_t line)
343 {
344     boost::throw_exception(boost::enable_error_info(unexpected_call())
345         << boost::throw_file(file)
346         << boost::throw_line(line)
347     );
348 }
349
350 void unexpected_call::throw_(const char* file, std::size_t line, std::string const& descr)
351 {
352     boost::throw_exception(boost::enable_error_info(unexpected_call(descr))
353         << boost::throw_file(file)
354         << boost::throw_line(line)
355     );
356 }
357
358 setup_error::setup_error() :
359     logic_error("The library is not initialized properly")
360 {
361 }
362
363 setup_error::setup_error(std::string const& descr) :
364     logic_error(descr)
365 {
366 }
367
368 setup_error::~setup_error() throw()
369 {
370 }
371
372 void setup_error::throw_(const char* file, std::size_t line)
373 {
374     boost::throw_exception(boost::enable_error_info(setup_error())
375         << boost::throw_file(file)
376         << boost::throw_line(line)
377     );
378 }
379
380 void setup_error::throw_(const char* file, std::size_t line, std::string const& descr)
381 {
382     boost::throw_exception(boost::enable_error_info(setup_error(descr))
383         << boost::throw_file(file)
384         << boost::throw_line(line)
385     );
386 }
387
388 limitation_error::limitation_error() :
389     logic_error("Boost.Log library limit reached")
390 {
391 }
392
393 limitation_error::limitation_error(std::string const& descr) :
394     logic_error(descr)
395 {
396 }
397
398 limitation_error::~limitation_error() throw()
399 {
400 }
401
402 void limitation_error::throw_(const char* file, std::size_t line)
403 {
404     boost::throw_exception(boost::enable_error_info(limitation_error())
405         << boost::throw_file(file)
406         << boost::throw_line(line)
407     );
408 }
409
410 void limitation_error::throw_(const char* file, std::size_t line, std::string const& descr)
411 {
412     boost::throw_exception(boost::enable_error_info(limitation_error(descr))
413         << boost::throw_file(file)
414         << boost::throw_line(line)
415     );
416 }
417
418 BOOST_LOG_CLOSE_NAMESPACE // namespace log
419
420 } // namespace boost
421
422 #ifdef _MSC_VER
423 #pragma warning(pop)
424 #endif
425
426 #include <boost/log/detail/footer.hpp>