patrick
/
plasp
Archived
1
0
Fork 0

Added class for PDDL parser exceptions.

This commit is contained in:
Patrick Lühne 2017-05-17 15:29:51 +02:00
parent 29f8ee0778
commit 8a103ea89d
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
1 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,82 @@
#ifndef __PDDL_PARSE__PARSER_EXCEPTION_H
#define __PDDL_PARSE__PARSER_EXCEPTION_H
#include <exception>
#include <string>
#include <tokenize/Stream.h>
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ParserException
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class ParserException: public std::exception
{
public:
explicit ParserException()
: ParserException("unspecified parser error")
{
}
explicit ParserException(const char *message)
: ParserException(static_cast<std::string>(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<std::string>(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