From 65f17438de5983ca010e10b4b24c5da65756a9b5 Mon Sep 17 00:00:00 2001 From: Teddy Date: Sun, 4 Aug 2013 11:50:41 +0800 Subject: added exception facilities --- exc.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 exc.h (limited to 'exc.h') diff --git a/exc.h b/exc.h new file mode 100644 index 0000000..7a6879d --- /dev/null +++ b/exc.h @@ -0,0 +1,37 @@ +#ifndef EXC_H +#define EXC_H + +#include "consts.h" +#include + +using std::string; + +/** @class GeneralError + * The top-level exception + */ +class GeneralError { + public: + virtual string get_msg() = 0; /**< Extract error message */ +}; + +class SyntaxError : public GeneralError { + protected: + string msg; /**< Error mesg */ + ErrCode code; /**< Error code */ + public: + + SyntaxError(ErrCode code); /**< Construct an SyntaxError */ + string get_msg(); /**< Get the error message */ +}; + +class TokenError : public SyntaxError { + public: + TokenError(string token, ErrCode code); /**< Construct an TokenError */ +}; + +class NormalError : public SyntaxError { + public: + NormalError(ErrCode code); +}; + +#endif -- cgit v1.2.3