diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-12-05 13:50:35 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2014-12-05 13:50:35 +0100 |
commit | 33f4b36bb9de2d34e2448d6ae5ea705717a6095f (patch) | |
tree | 6a1f63ea7a9aa6a89433d1fbef3464baffbdfc86 /src | |
parent | a23c51bcb1b8d85b1ea06a7a16729fa4b87d8fd4 (diff) |
added no constructor for LoggableException
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CSSParser.cpp | 23 | ||||
-rw-r--r-- | src/core/Exceptions.cpp | 4 | ||||
-rw-r--r-- | src/core/Exceptions.hpp | 63 |
3 files changed, 49 insertions, 41 deletions
diff --git a/src/core/CSSParser.cpp b/src/core/CSSParser.cpp index 3a86f45..b762844 100644 --- a/src/core/CSSParser.cpp +++ b/src/core/CSSParser.cpp @@ -124,11 +124,8 @@ void CSSParser::parseSelectors(Rooted<SelectorNode> root, // as the parseSelector is supposed to parse only a SelectorPath // there should not be more than one leaf. throw LoggableException{ - "Internal Error: More than one leaf in SelectorPath!", "", - // TODO: Line handling? - // tokenizer.getInput().getLine(), - // tokenizer.getInput().getColumn() - }; + "Internal Error: More than one leaf in SelectorPath!", true, + tokenizer.getInput()}; } // if we find a comma, we can proceed parsing selectors. Token t; @@ -293,19 +290,11 @@ bool CSSParser::expect(int expectedType, CodeTokenizer &tokenizer, Token &t, if (end || t.tokenId != expectedType) { if (force) { if (end) { - throw LoggableException{ - "Unexpected end of file!", "", - // TODO: Line handling? - // tokenizer.getInput().getLine(), - // tokenizer.getInput().getColumn() - }; + throw LoggableException{"Unexpected end of file!", true, + tokenizer.getInput()}; } else { - throw LoggableException{ - "Unexpected token!", "", - // TODO: Line handling? - // tokenizer.getInput().getLine(), - // tokenizer.getInput().getColumn() - }; + throw LoggableException{"Unexpected token!", true, + tokenizer.getInput()}; } } else { tokenizer.resetPeek(); diff --git a/src/core/Exceptions.cpp b/src/core/Exceptions.cpp index 735dac6..206f5b2 100644 --- a/src/core/Exceptions.cpp +++ b/src/core/Exceptions.cpp @@ -25,8 +25,8 @@ namespace ousia { /* Class LoggableException */ std::string LoggableException::formatMessage(const std::string &msg, - const std::string &file, int line, - int column, bool fatal) + const std::string &file, + bool fatal, int line, int column) { std::stringstream ss; ss << "error "; diff --git a/src/core/Exceptions.hpp b/src/core/Exceptions.hpp index f1bb95a..a5d50d5 100644 --- a/src/core/Exceptions.hpp +++ b/src/core/Exceptions.hpp @@ -81,8 +81,8 @@ private: * reported to the runtime environment. */ static std::string formatMessage(const std::string &msg, - const std::string &file, int line, - int column, bool fatal); + const std::string &file, bool fatal, + int line, int column); public: /** @@ -96,6 +96,12 @@ public: const std::string file; /** + * If set to true, the exception should not be handled as recoverable error + * but as "fatal" error. + */ + const bool fatal; + + /** * Line at which the exception occured. Negative values are ignored. */ const int line; @@ -106,12 +112,6 @@ public: const int column; /** - * If set to true, the exception should not be handled as recoverable error - * but as "fatal" error. - */ - const bool fatal; - - /** * Constructor of the LoggableException class. * * @param msg contains the error message. @@ -120,14 +120,14 @@ public: * @param column is the column in the above file the message refers to. * @param fatal shoudl be set to true if the error is non-recoverable. */ - LoggableException(std::string msg, std::string file, int line = -1, - int column = -1, bool fatal = true) - : OusiaException(formatMessage(msg, file, line, column, fatal)), + LoggableException(std::string msg, std::string file, bool fatal, + int line = -1, int column = -1) + : OusiaException(formatMessage(msg, file, fatal, line, column)), msg(std::move(msg)), file(std::move(file)), + fatal(fatal), line(line), - column(column), - fatal(fatal) + column(column) { } @@ -135,17 +135,16 @@ public: * Constructor of the LoggableException class with empty file. * * @param msg contains the error message. + * @param fatal should be set to true if the error is non-recoverable. * @param line is the line in the above file the message refers to. * @param column is the column in the above file the message refers to. - * @param fatal shoudl be set to true if the error is non-recoverable. */ - LoggableException(std::string msg, int line = -1, int column = -1, - bool fatal = true) - : OusiaException(formatMessage(msg, "", line, column, fatal)), + LoggableException(std::string msg, bool fatal, int line = -1, int column = -1) + : OusiaException(formatMessage(msg, "", fatal, line, column)), msg(std::move(msg)), + fatal(fatal), line(line), - column(column), - fatal(fatal) + column(column) { } @@ -156,11 +155,31 @@ public: * @param fatal should be set to true if the error is non-recoverable. */ LoggableException(std::string msg, bool fatal) - : OusiaException(formatMessage(msg, "", -1, -1, fatal)), + : OusiaException(formatMessage(msg, "", fatal, -1, -1)), msg(std::move(msg)), + fatal(fatal), line(-1), - column(-1), - fatal(fatal) + column(-1) + { + } + + /** + * Constructor of the LoggableException class with empty file and an + * position object. + * + * @param msg is the actual log message. + * @param pos is a const reference to a variable which provides position + * information. + * @param fatal should be set to true if the error is non-recoverable. + */ + template <class PosType> + LoggableException(std::string msg, bool fatal, const PosType &pos) + : OusiaException( + formatMessage(msg, "", fatal, pos.getLine(), pos.getColumn())), + msg(std::move(msg)), + fatal(fatal), + line(pos.getLine()), + column(pos.getColumn()) { } }; |