From 514cb71a6a3e116c229c5dc874369f8632530dc7 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 27 Apr 2021 11:23:17 +0200 Subject: Squashed 'deps/inja/' content from commit 811e173 git-subtree-dir: deps/inja git-subtree-split: 811e1730e13bca4ea1805a42d5f0a4b5c91046e1 --- include/inja/exceptions.hpp | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 include/inja/exceptions.hpp (limited to 'include/inja/exceptions.hpp') diff --git a/include/inja/exceptions.hpp b/include/inja/exceptions.hpp new file mode 100644 index 0000000..2784da8 --- /dev/null +++ b/include/inja/exceptions.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2020 Pantor. All rights reserved. + +#ifndef INCLUDE_INJA_EXCEPTIONS_HPP_ +#define INCLUDE_INJA_EXCEPTIONS_HPP_ + +#include +#include + +namespace inja { + +struct SourceLocation { + size_t line; + size_t column; +}; + +struct InjaError : public std::runtime_error { + const std::string type; + const std::string message; + + const SourceLocation location; + + explicit InjaError(const std::string &type, const std::string &message) + : std::runtime_error("[inja.exception." + type + "] " + message), type(type), message(message), location({0, 0}) {} + + explicit InjaError(const std::string &type, const std::string &message, SourceLocation location) + : std::runtime_error("[inja.exception." + type + "] (at " + std::to_string(location.line) + ":" + + std::to_string(location.column) + ") " + message), + type(type), message(message), location(location) {} +}; + +struct ParserError : public InjaError { + explicit ParserError(const std::string &message, SourceLocation location) : InjaError("parser_error", message, location) {} +}; + +struct RenderError : public InjaError { + explicit RenderError(const std::string &message, SourceLocation location) : InjaError("render_error", message, location) {} +}; + +struct FileError : public InjaError { + explicit FileError(const std::string &message) : InjaError("file_error", message) {} + explicit FileError(const std::string &message, SourceLocation location) : InjaError("file_error", message, location) {} +}; + +struct JsonError : public InjaError { + explicit JsonError(const std::string &message, SourceLocation location) : InjaError("json_error", message, location) {} +}; + +} // namespace inja + +#endif // INCLUDE_INJA_EXCEPTIONS_HPP_ -- cgit v1.2.3