summaryrefslogtreecommitdiff
path: root/error.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-04-12 01:40:49 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-05-08 02:50:19 -0400
commitb45037e334ca336498217d4f54756c319c074d7b (patch)
treed0f8338df6c8adf86debcdcf236a25bbdd8d305b /error.h
parent289cc97d45bbd3a8cdfcc3371ade71715b75b000 (diff)
downloadfork-ledger-b45037e334ca336498217d4f54756c319c074d7b.tar.gz
fork-ledger-b45037e334ca336498217d4f54756c319c074d7b.tar.bz2
fork-ledger-b45037e334ca336498217d4f54756c319c074d7b.zip
Migrated over both code and build environment from was-v3.0 branch.
Diffstat (limited to 'error.h')
-rw-r--r--error.h33
1 files changed, 19 insertions, 14 deletions
diff --git a/error.h b/error.h
index 7f77db0f..771e9f10 100644
--- a/error.h
+++ b/error.h
@@ -7,6 +7,8 @@
#include <sstream>
#include <list>
+namespace ledger {
+
class error_context
{
public:
@@ -63,15 +65,13 @@ class line_context : public error_context {
//////////////////////////////////////////////////////////////////////
-class str_exception : public std::exception {
- protected:
- std::string reason;
+class str_exception : public std::logic_error {
public:
std::list<error_context *> context;
- str_exception(const std::string& _reason,
+ str_exception(const std::string& why,
error_context * ctxt = NULL) throw()
- : reason(_reason) {
+ : std::logic_error(why) {
if (ctxt)
context.push_back(ctxt);
}
@@ -95,31 +95,36 @@ class str_exception : public std::exception {
(*i)->describe(out);
}
}
+};
- virtual const char* what() const throw() {
- return reason.c_str();
+#define DECLARE_EXCEPTION(kind, name) \
+ class name : public kind { \
+ public: \
+ name(const std::string& why, error_context * ctxt = NULL) throw() \
+ : kind(why, ctxt) {} \
}
-};
class error : public str_exception {
public:
- error(const std::string& reason, error_context * ctxt = NULL) throw()
- : str_exception(reason, ctxt) {}
+ error(const std::string& why, error_context * ctxt = NULL) throw()
+ : str_exception(why, ctxt) {}
virtual ~error() throw() {}
};
class fatal : public str_exception {
public:
- fatal(const std::string& reason, error_context * ctxt = NULL) throw()
- : str_exception(reason, ctxt) {}
+ fatal(const std::string& why, error_context * ctxt = NULL) throw()
+ : str_exception(why, ctxt) {}
virtual ~fatal() throw() {}
};
class fatal_assert : public fatal {
public:
- fatal_assert(const std::string& reason, error_context * ctxt = NULL) throw()
- : fatal(std::string("assertion failed '") + reason + "'", ctxt) {}
+ fatal_assert(const std::string& why, error_context * ctxt = NULL) throw()
+ : fatal(std::string("assertion failed '") + why + "'", ctxt) {}
virtual ~fatal_assert() throw() {}
};
+} // namespace ledger
+
#endif // _ERROR_H