From 8a103ea89de909a6f99848840d30f1bb1a55676d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 17 May 2017 15:29:51 +0200 Subject: [PATCH] Added class for PDDL parser exceptions. --- .../include/pddlparse/ParserException.h | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 lib/pddlparse/include/pddlparse/ParserException.h diff --git a/lib/pddlparse/include/pddlparse/ParserException.h b/lib/pddlparse/include/pddlparse/ParserException.h new file mode 100644 index 0000000..b0630bb --- /dev/null +++ b/lib/pddlparse/include/pddlparse/ParserException.h @@ -0,0 +1,82 @@ +#ifndef __PDDL_PARSE__PARSER_EXCEPTION_H +#define __PDDL_PARSE__PARSER_EXCEPTION_H + +#include +#include + +#include + +namespace pddl +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// ParserException +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class ParserException: public std::exception +{ + public: + explicit ParserException() + : ParserException("unspecified parser error") + { + } + + explicit ParserException(const char *message) + : ParserException(static_cast(message)) + { + } + + explicit ParserException(const std::string &message) + : m_message{message} + { + } + + explicit ParserException(const tokenize::Location &location) + : ParserException(location, "unspecified parser error") + { + } + + explicit ParserException(const tokenize::Location &location, const char *message) + : ParserException(location, static_cast(message)) + { + } + + explicit ParserException(const tokenize::Location &location, const std::string &message) + : m_location{location}, + m_message{message}, + // TODO: refactor + m_plainMessage{std::string(m_location.sectionStart) + ":" + std::to_string(m_location.rowStart) + + ":" + std::to_string(m_location.columnStart) + " " + m_message} + { + } + + ~ParserException() noexcept = default; + + const char *what() const throw() + { + return m_plainMessage.c_str(); + } + + const tokenize::Location &location() const + { + return m_location; + } + + const std::string &message() const + { + return m_message; + } + + private: + tokenize::Location m_location; + std::string m_message; + std::string m_plainMessage; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} + +#endif