From b45037e334ca336498217d4f54756c319c074d7b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 12 Apr 2008 01:40:49 -0400 Subject: Migrated over both code and build environment from was-v3.0 branch. --- error.h | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'error.h') diff --git a/error.h b/error.h index 7f77db0f..771e9f10 100644 --- a/error.h +++ b/error.h @@ -7,6 +7,8 @@ #include #include +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 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 -- cgit v1.2.3