]> git.tdb.fi Git - libs/datafile.git/blob - source/except.cpp
Move all exception classes to a common header
[libs/datafile.git] / source / except.cpp
1 #include <typeinfo>
2 #include <msp/debug/demangle.h>
3 #include <msp/strings/format.h>
4 #include "except.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace DataFile {
10
11 data_error::data_error(const string &s, unsigned l, const string &w):
12         runtime_error(make_what(s, l, w)),
13         source(s),
14         line(l)
15 { }
16
17 data_error::data_error(const string &s, unsigned l, const exception &e):
18         runtime_error(make_what(s, l, format("%s (%s)", Debug::demangle(typeid(e).name()), e.what()))),
19         source(s),
20         line(l)
21 { }
22
23 string data_error::make_what(const string &s, unsigned l, const string &w)
24 {
25         if(l)
26                 return format("%s:%d: %s", s, l, w);
27         else
28                 return format("%s: %s", s, w);
29 }
30
31
32 parse_error::parse_error(const string &t):
33         runtime_error(t.empty() ? "at end of input" : format("after '%s'", t))
34 { }
35
36
37 syntax_error::syntax_error(const string &t):
38         runtime_error(t.empty() ? "at end of input" : format("at '%s'", t))
39 { }
40
41
42 bad_definition::bad_definition(const string &w):
43         runtime_error(w)
44 { }
45
46
47 nesting_error::nesting_error(const string &w):
48         logic_error(w)
49 { }
50
51 } // namespace DataFile
52 } // namespace Msp