1 /*
2  * Hunt - A high-level D Programming Language Web framework that encourages rapid development and clean, pragmatic design.
3  *
4  * Copyright (C) 2015-2019, HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.framework.view.Exception;
13 
14 private
15 {
16     import hunt.framework.view.Lexer : Position;
17 }
18 
19 
20 class TemplateException : Exception
21 {
22     this(string msg, string file = __FILE__, size_t line = __LINE__)
23     {
24         super(msg, file, line);
25     }
26 }
27 
28 
29 
30 class TemplateLexerException : TemplateException
31 {
32     this(string msg, string file = __FILE__, size_t line = __LINE__)
33     {
34         super(msg, file, line);
35     }
36 }
37 
38 
39 
40 class TemplateParserException : TemplateException
41 {
42     this(string msg, string file = __FILE__, size_t line = __LINE__)
43     {
44         super(msg, file, line);
45     }
46 }
47 
48 
49 
50 class TemplateRenderException : TemplateException
51 {
52     this(string msg, string file = __FILE__, size_t line = __LINE__)
53     {
54         super(msg, file, line);
55     }
56 }
57 
58 
59 void assertTemplate(E : TemplateException)(bool expr, string msg = "", Position pos = Position.init, string file = __FILE__, size_t line = __LINE__)
60 {
61     if (!expr)
62     {
63         if (pos == Position.init)
64             throw new E(msg, file, line);
65         else
66             throw new E(pos.toString ~ ": " ~ msg, file, line); 
67     }
68 }
69 
70 
71 alias assertTemplateException = assertTemplate!TemplateException;
72 alias assertTemplateLexer = assertTemplate!TemplateLexerException;
73 alias assertTemplateParser = assertTemplate!TemplateParserException;
74 alias assertTemplateRender = assertTemplate!TemplateRenderException;