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