1 /** 2 * Djinja Exceptions 3 * 4 * Copyright: 5 * Copyright (c) 2018, Maxim Tyapkin. 6 * Authors: 7 * Maxim Tyapkin 8 * License: 9 * This software is licensed under the terms of the BSD 3-clause license. 10 * The full terms of the license can be found in the LICENSE.md file. 11 */ 12 13 module djinja.exception; 14 15 private 16 { 17 import djinja.lexer : Position; 18 } 19 20 21 class JinjaException : Exception 22 { 23 this(string msg, string file = __FILE__, size_t line = __LINE__) 24 { 25 super(msg, file, line); 26 } 27 } 28 29 30 31 class JinjaLexerException : JinjaException 32 { 33 this(string msg, string file = __FILE__, size_t line = __LINE__) 34 { 35 super(msg, file, line); 36 } 37 } 38 39 40 41 class JinjaParserException : JinjaException 42 { 43 this(string msg, string file = __FILE__, size_t line = __LINE__) 44 { 45 super(msg, file, line); 46 } 47 } 48 49 50 51 class JinjaRenderException : JinjaException 52 { 53 this(string msg, string file = __FILE__, size_t line = __LINE__) 54 { 55 super(msg, file, line); 56 } 57 } 58 59 60 void assertJinja(E : JinjaException)(bool expr, string msg = "", Position pos = Position.init, string file = __FILE__, size_t line = __LINE__) 61 { 62 if (!expr) 63 { 64 if (pos == Position.init) 65 throw new E(msg, file, line); 66 else 67 throw new E(pos.toString ~ ": " ~ msg, file, line); 68 } 69 } 70 71 72 alias assertJinjaException = assertJinja!JinjaException; 73 alias assertJinjaLexer = assertJinja!JinjaLexerException; 74 alias assertJinjaParser = assertJinja!JinjaParserException; 75 alias assertJinjaRender = assertJinja!JinjaRenderException;