diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-04-27 11:23:17 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-04-27 11:23:17 +0200 |
commit | 514cb71a6a3e116c229c5dc874369f8632530dc7 (patch) | |
tree | dbc61581e04809fca19fefb3f4954b76e1e3e2c8 /include/inja/exceptions.hpp |
Squashed 'deps/inja/' content from commit 811e173
git-subtree-dir: deps/inja
git-subtree-split: 811e1730e13bca4ea1805a42d5f0a4b5c91046e1
Diffstat (limited to 'include/inja/exceptions.hpp')
-rw-r--r-- | include/inja/exceptions.hpp | 50 |
1 files changed, 50 insertions, 0 deletions
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 <stdexcept> +#include <string> + +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_ |