summaryrefslogtreecommitdiffabout
path: root/lib/exception.cc
authorMichael Krelin <hacker@klever.net>2005-01-29 19:41:34 (UTC)
committer Michael Krelin <hacker@klever.net>2005-01-29 19:41:34 (UTC)
commitee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e (patch) (side-by-side diff)
treebe8029ce4a68870d991651927a27df8ee9d89617 /lib/exception.cc
parentd851b00e16839d6ec14da3a5c442be62ca868bba (diff)
downloadkonforka-ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e.zip
konforka-ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e.tar.gz
konforka-ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e.tar.bz2
initial commit.0.0
Diffstat (limited to 'lib/exception.cc') (more/less context) (show 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 @@
+#include <string.h>
+#include <errno.h>
+#include "konforka/exception.h"
+
+namespace konforka {
+
+ /*
+ * code_point
+ */
+
+ code_point::code_point(const string& w)
+ : where(w), line(-1) { }
+ code_point::code_point(const string& fi,const string& fu,int l)
+ : file(fi), function(fu), line(l) {
+ make_where();
+ }
+
+ const char *code_point::c_str() const throw() {
+ return where.c_str();
+ }
+
+ void code_point::make_where() {
+ static char tmp[8];
+ snprintf(tmp,sizeof(tmp),"%d",line);
+ where = file + ":" + tmp + " [" + function + "]";
+ }
+
+ /*
+ * exception
+ */
+
+ exception::exception(const string& whe,const string& wha)
+ : _where(whe), _what(wha) { }
+ exception::exception(const string& fi,const string& fu,int l,const string& w)
+ : _where(fi,fu,l), _what(w) { }
+ exception::~exception() throw() { }
+
+ const char *exception::where() const throw() {
+ return _where.c_str();
+ }
+ const char *exception::what() const throw() {
+ return _what.c_str();
+ }
+
+ void exception::see(const string& w) {
+ _seen.push_back(code_point(w));
+ }
+ void exception::see(const string& fi,const string& fu,int l) {
+ _seen.push_back(code_point(fi,fu,l));
+ }
+
+ /*
+ * system_error
+ */
+
+ system_error::system_error(const string& whe,const string& wha)
+ : _errno(errno), exception(whe,wha) { }
+ system_error::system_error(const string& fi,const string& fu,int l,const string& w)
+ : _errno(errno), exception(fi,fu,l,w) { }
+ system_error::~system_error() throw() { }
+
+ const char *system_error::why() const throw() {
+ return strerror(errno); // TODO: strerror_r
+ }
+
+}