1 /** 2 * Copyright © DiamondMVC 2018 3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 */ 6 module diamond.errors.exceptions.viewexception; 7 8 import diamond.core.apptype; 9 10 static if (!isWebApi) 11 { 12 /// Exception thrown by a view. 13 class ViewException : Exception 14 { 15 private: 16 /// The view name. 17 string _viewName; 18 /// The actual exception thrown. 19 Exception _exception; 20 21 public: 22 /** 23 * Creates a new view exception. 24 * Params: 25 * viewName = The name of the view that threw the error. 26 * exception = The exception. 27 * fn = The file. 28 * ln = The line. 29 */ 30 this(string viewName, Exception exception, string fn = __FILE__, size_t ln = __LINE__) 31 { 32 _viewName = viewName; 33 _exception = exception; 34 35 super("...", fn, ln); 36 } 37 38 /** 39 * Retrieves a string equivalent to the exception text. 40 * Returns: 41 * A string equivalent to the exception text. 42 */ 43 override string toString() 44 { 45 return "view: " ~ _viewName ~ "\r\n\r\n" ~ _exception.toString(); 46 } 47 } 48 49 /// Error thrown by a view. 50 class ViewError : Error 51 { 52 private: 53 /// The view name. 54 string _viewName; 55 /// The actual error thrown. 56 Throwable _error; 57 58 public: 59 /** 60 * Creates a new view error. 61 * Params: 62 * viewName = The name of the view that threw the error. 63 * error = The error. 64 * fn = The file. 65 * ln = The line. 66 */ 67 this(string viewName, Throwable error, string fn = __FILE__, size_t ln = __LINE__) 68 { 69 _viewName = viewName; 70 _error = error; 71 72 super("...", fn, ln); 73 } 74 75 /** 76 * Retrieves a string equivalent to the error text. 77 * Returns: 78 * A string equivalent to the error text. 79 */ 80 override string toString() 81 { 82 return "view: " ~ _viewName ~ "\r\n\r\n" ~ _error.toString(); 83 } 84 } 85 }