Inja 3.3.0
A Template Engine for Modern C++
Loading...
Searching...
No Matches
exceptions.hpp
1#ifndef INCLUDE_INJA_EXCEPTIONS_HPP_
2#define INCLUDE_INJA_EXCEPTIONS_HPP_
3
4#include <stdexcept>
5#include <string>
6
7namespace inja {
8
10 size_t line;
11 size_t column;
12};
13
14struct InjaError : public std::runtime_error {
15 const std::string type;
16 const std::string message;
17
18 const SourceLocation location;
19
20 explicit InjaError(const std::string &type, const std::string &message)
21 : std::runtime_error("[inja.exception." + type + "] " + message), type(type), message(message), location({0, 0}) {}
22
23 explicit InjaError(const std::string &type, const std::string &message, SourceLocation location)
24 : std::runtime_error("[inja.exception." + type + "] (at " + std::to_string(location.line) + ":" +
25 std::to_string(location.column) + ") " + message),
26 type(type), message(message), location(location) {}
27};
28
29struct ParserError : public InjaError {
30 explicit ParserError(const std::string &message, SourceLocation location) : InjaError("parser_error", message, location) {}
31};
32
33struct RenderError : public InjaError {
34 explicit RenderError(const std::string &message, SourceLocation location) : InjaError("render_error", message, location) {}
35};
36
37struct FileError : public InjaError {
38 explicit FileError(const std::string &message) : InjaError("file_error", message) {}
39 explicit FileError(const std::string &message, SourceLocation location) : InjaError("file_error", message, location) {}
40};
41
42struct JsonError : public InjaError {
43 explicit JsonError(const std::string &message, SourceLocation location) : InjaError("json_error", message, location) {}
44};
45
46} // namespace inja
47
48#endif // INCLUDE_INJA_EXCEPTIONS_HPP_
Definition: exceptions.hpp:37
Definition: exceptions.hpp:14
Definition: exceptions.hpp:42
Definition: exceptions.hpp:29
Definition: exceptions.hpp:33
Definition: exceptions.hpp:9