|
5 | 5 |
|
6 | 6 | #include <nlohmann/json.hpp> |
7 | 7 |
|
| 8 | +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(INJA_NOEXCEPTION) |
| 9 | + #define INJA_THROW(exception) throw exception |
| 10 | +#else |
| 11 | + #include <cstdlib> |
| 12 | + #define INJA_THROW(exception) std::abort() |
| 13 | +#endif |
| 14 | + |
8 | 15 | // #include "environment.hpp" |
9 | 16 | // Copyright (c) 2019 Pantor. All rights reserved. |
10 | 17 |
|
@@ -1838,7 +1845,7 @@ inline void open_file_or_throw(const std::string &path, std::ifstream &file) { |
1838 | 1845 | try { |
1839 | 1846 | file.open(path); |
1840 | 1847 | } catch (const std::ios_base::failure & /*e*/) { |
1841 | | - throw FileError("failed accessing file at '" + path + "'"); |
| 1848 | + INJA_THROW(FileError("failed accessing file at '" + path + "'")); |
1842 | 1849 | } |
1843 | 1850 | } |
1844 | 1851 |
|
@@ -2780,7 +2787,7 @@ class Parser { |
2780 | 2787 | std::stack<ForStatementNode*> for_statement_stack; |
2781 | 2788 |
|
2782 | 2789 | void throw_parser_error(const std::string &message) { |
2783 | | - throw ParserError(message, lexer.current_position()); |
| 2790 | + INJA_THROW(ParserError(message, lexer.current_position())); |
2784 | 2791 | } |
2785 | 2792 |
|
2786 | 2793 | void get_next_token() { |
@@ -3409,7 +3416,7 @@ class Renderer : public NodeVisitor { |
3409 | 3416 |
|
3410 | 3417 | void throw_renderer_error(const std::string &message, const AstNode& node) { |
3411 | 3418 | SourceLocation loc = get_source_location(current_template->content, node.pos); |
3412 | | - throw RenderError(message, loc); |
| 3419 | + INJA_THROW(RenderError(message, loc)); |
3413 | 3420 | } |
3414 | 3421 |
|
3415 | 3422 | template<size_t N, bool throw_not_found=true> |
|
0 commit comments