-rw-r--r-- | lib/exception.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/exception.cc b/lib/exception.cc index 65302bf..e03f818 100644 --- a/lib/exception.cc +++ b/lib/exception.cc | |||
@@ -1,66 +1,67 @@ | |||
1 | #include <stdio.h> | ||
1 | #include <string.h> | 2 | #include <string.h> |
2 | #include <errno.h> | 3 | #include <errno.h> |
3 | #include "konforka/exception.h" | 4 | #include "konforka/exception.h" |
4 | 5 | ||
5 | namespace konforka { | 6 | namespace konforka { |
6 | 7 | ||
7 | /* | 8 | /* |
8 | * code_point | 9 | * code_point |
9 | */ | 10 | */ |
10 | 11 | ||
11 | code_point::code_point(const string& w) | 12 | code_point::code_point(const string& w) |
12 | : where(w), line(-1) { } | 13 | : where(w), line(-1) { } |
13 | code_point::code_point(const string& fi,const string& fu,int l) | 14 | code_point::code_point(const string& fi,const string& fu,int l) |
14 | : file(fi), function(fu), line(l) { | 15 | : file(fi), function(fu), line(l) { |
15 | make_where(); | 16 | make_where(); |
16 | } | 17 | } |
17 | 18 | ||
18 | const char *code_point::c_str() const throw() { | 19 | const char *code_point::c_str() const throw() { |
19 | return where.c_str(); | 20 | return where.c_str(); |
20 | } | 21 | } |
21 | 22 | ||
22 | void code_point::make_where() { | 23 | void code_point::make_where() { |
23 | static char tmp[8]; | 24 | static char tmp[8]; |
24 | snprintf(tmp,sizeof(tmp),"%d",line); | 25 | snprintf(tmp,sizeof(tmp),"%d",line); |
25 | where = file + ":" + tmp + " [" + function + "]"; | 26 | where = file + ":" + tmp + " [" + function + "]"; |
26 | } | 27 | } |
27 | 28 | ||
28 | /* | 29 | /* |
29 | * exception | 30 | * exception |
30 | */ | 31 | */ |
31 | 32 | ||
32 | exception::exception(const string& whe,const string& wha) | 33 | exception::exception(const string& whe,const string& wha) |
33 | : _where(whe), _what(wha) { } | 34 | : _where(whe), _what(wha) { } |
34 | exception::exception(const string& fi,const string& fu,int l,const string& w) | 35 | exception::exception(const string& fi,const string& fu,int l,const string& w) |
35 | : _where(fi,fu,l), _what(w) { } | 36 | : _where(fi,fu,l), _what(w) { } |
36 | exception::~exception() throw() { } | 37 | exception::~exception() throw() { } |
37 | 38 | ||
38 | const char *exception::where() const throw() { | 39 | const char *exception::where() const throw() { |
39 | return _where.c_str(); | 40 | return _where.c_str(); |
40 | } | 41 | } |
41 | const char *exception::what() const throw() { | 42 | const char *exception::what() const throw() { |
42 | return _what.c_str(); | 43 | return _what.c_str(); |
43 | } | 44 | } |
44 | 45 | ||
45 | void exception::see(const string& w) { | 46 | void exception::see(const string& w) { |
46 | _seen.push_back(code_point(w)); | 47 | _seen.push_back(code_point(w)); |
47 | } | 48 | } |
48 | void exception::see(const string& fi,const string& fu,int l) { | 49 | void exception::see(const string& fi,const string& fu,int l) { |
49 | _seen.push_back(code_point(fi,fu,l)); | 50 | _seen.push_back(code_point(fi,fu,l)); |
50 | } | 51 | } |
51 | 52 | ||
52 | /* | 53 | /* |
53 | * system_error | 54 | * system_error |
54 | */ | 55 | */ |
55 | 56 | ||
56 | system_error::system_error(const string& whe,const string& wha) | 57 | system_error::system_error(const string& whe,const string& wha) |
57 | : _errno(errno), exception(whe,wha) { } | 58 | : _errno(errno), exception(whe,wha) { } |
58 | system_error::system_error(const string& fi,const string& fu,int l,const string& w) | 59 | system_error::system_error(const string& fi,const string& fu,int l,const string& w) |
59 | : _errno(errno), exception(fi,fu,l,w) { } | 60 | : _errno(errno), exception(fi,fu,l,w) { } |
60 | system_error::~system_error() throw() { } | 61 | system_error::~system_error() throw() { } |
61 | 62 | ||
62 | const char *system_error::why() const throw() { | 63 | const char *system_error::why() const throw() { |
63 | return strerror(errno); // TODO: strerror_r | 64 | return strerror(errno); // TODO: strerror_r |
64 | } | 65 | } |
65 | 66 | ||
66 | } | 67 | } |