1 /** 2 License: 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 Authors: 28 Alexandru Ermicioi 29 **/ 30 module aermicioi.aedi_property_reader.convertor.exception; 31 32 import aermicioi.aedi.exception.di_exception; 33 import aermicioi.aedi.util.range; 34 35 /** 36 Exception thrown when a problem related to conversion appeared. 37 **/ 38 class ConvertorException : Exception { 39 /** 40 * Creates a new instance of Exception. The next parameter is used 41 * internally and should always be $(D null) when passed by user code. 42 * This constructor does not automatically throw the newly-created 43 * Exception; the $(D throw) statement should be used for that purpose. 44 */ 45 @nogc @safe pure nothrow this( 46 string msg = "", 47 string file = __FILE__, 48 size_t line = __LINE__, 49 Throwable next = null 50 ) { 51 super(msg, file, line, next); 52 } 53 54 /** 55 ditto 56 **/ 57 @nogc @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) 58 { 59 super(msg, file, line, next); 60 } 61 62 /** 63 ditto 64 **/ 65 @nogc @safe pure nothrow this(Throwable next, string msg = "", string file = __FILE__, size_t line = __LINE__) 66 { 67 super(msg, file, line, next); 68 } 69 70 void pushMessage(scope void delegate(in char[]) sink) const @system { 71 sink(this.message); 72 } 73 74 mixin AdvancedExceptionPrinting!(); 75 } 76 77 /** 78 Exception thrown when property is not found in document/component 79 **/ 80 class NotFoundException : ConvertorException { 81 string property; 82 string component; 83 84 /** 85 * Creates a new instance of Exception. The next parameter is used 86 * internally and should always be $(D null) when passed by user code. 87 * This constructor does not automatically throw the newly-created 88 * Exception; the $(D throw) statement should be used for that purpose. 89 */ 90 @nogc @safe pure nothrow this( 91 string msg, 92 string property, 93 string component, 94 string file = __FILE__, 95 size_t line = __LINE__, 96 Throwable next = null 97 ) { 98 this.property = property; 99 this.component = component; 100 super(msg, file, line, next); 101 } 102 103 /** 104 ditto 105 **/ 106 @nogc @safe pure nothrow this( 107 string msg, 108 string property, 109 string component, 110 Throwable next, 111 string file = __FILE__, 112 size_t line = __LINE__ 113 ) { 114 this.property = property; 115 this.component = component; 116 super(msg, file, line, next); 117 } 118 119 /** 120 ditto 121 **/ 122 @nogc @safe pure nothrow this(Throwable next, string msg = "", string file = __FILE__, size_t line = __LINE__) 123 { 124 super(msg, file, line, next); 125 } 126 127 override void pushMessage(scope void delegate(in char[]) sink) const @system { 128 import std.algorithm : substitute; 129 import std.utf : byChar; 130 auto substituted = this.msg.substitute("${property}", property, "${component}", component).byChar; 131 132 while (!substituted.empty) { 133 auto buffer = BufferSink!(char[256])(); 134 import std.range; 135 buffer.put(substituted); 136 137 sink(buffer.slice); 138 } 139 } 140 } 141 142 143 /** 144 Exception thrown when property is not found in document/component 145 **/ 146 class InvalidCastException : ConvertorException { 147 TypeInfo from; 148 TypeInfo to; 149 150 /** 151 * Creates a new instance of Exception. The next parameter is used 152 * internally and should always be $(D null) when passed by user code. 153 * This constructor does not automatically throw the newly-created 154 * Exception; the $(D throw) statement should be used for that purpose. 155 */ 156 @nogc @safe pure nothrow this( 157 string msg, 158 TypeInfo from, 159 TypeInfo to, 160 string file = __FILE__, 161 size_t line = __LINE__, 162 Throwable next = null 163 ) { 164 this.from = from; 165 this.to = to; 166 super(msg, file, line, next); 167 } 168 169 /** 170 ditto 171 **/ 172 @nogc @safe pure nothrow this( 173 string msg, 174 TypeInfo from, 175 TypeInfo to, 176 Throwable next, 177 string file = __FILE__, 178 size_t line = __LINE__ 179 ) { 180 this.from = from; 181 this.to = to; 182 super(msg, file, line, next); 183 } 184 185 /** 186 ditto 187 **/ 188 @nogc @safe pure nothrow this(Throwable next, string msg = "", string file = __FILE__, size_t line = __LINE__) 189 { 190 super(msg, file, line, next); 191 } 192 193 override void pushMessage(scope void delegate(in char[]) sink) const @system { 194 import std.algorithm : substitute; 195 import std.utf : byChar; 196 auto substituted = this.msg.substitute("${from}", from.toString, "${to}", to.toString).byChar; 197 198 while (!substituted.empty) { 199 auto buffer = BufferSink!(char[256])(); 200 import std.range; 201 buffer.put(substituted); 202 203 sink(buffer.slice); 204 } 205 } 206 } 207 208 /** 209 Exception thrown when passed argument is of wrong type. 210 **/ 211 class InvalidArgumentException : Exception { 212 /** 213 * Creates a new instance of Exception. The next parameter is used 214 * internally and should always be $(D null) when passed by user code. 215 * This constructor does not automatically throw the newly-created 216 * Exception; the $(D throw) statement should be used for that purpose. 217 */ 218 @nogc @safe pure nothrow this( 219 string msg = "", 220 string file = __FILE__, 221 size_t line = __LINE__, 222 Throwable next = null 223 ) { 224 super(msg, file, line, next); 225 } 226 227 /** 228 ditto 229 **/ 230 @nogc @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) 231 { 232 super(msg, file, line, next); 233 } 234 235 /** 236 ditto 237 **/ 238 @nogc @safe pure nothrow this(Throwable next, string msg = "", string file = __FILE__, size_t line = __LINE__) 239 { 240 super(msg, file, line, next); 241 } 242 }