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