1 /* 2 * Geario - A cross-platform abstraction library with asynchronous I/O. 3 * 4 * Copyright (C) 2021-2022 Kerisy.com 5 * 6 * Website: https://www.kerisy.com 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module geario.Exceptions; 13 14 import core.exception; 15 import std.exception; 16 17 void implementationMissing(string name = __FUNCTION__, string file = __FILE__, int line = __LINE__)( 18 bool CanThrow = true) { 19 if (CanThrow) 20 throw new Exception("Implementation missing: " ~ name, file, line); 21 else { 22 version (Posix) { 23 import std.stdio; 24 25 enum PRINT_COLOR_NONE = "\033[m"; 26 enum PRINT_COLOR_YELLOW = "\033[1;33m"; 27 stderr.writefln(PRINT_COLOR_YELLOW ~ "Implementation missing %s, in %s:%d" ~ PRINT_COLOR_NONE, 28 name, file, line); 29 } else version(Windows) { 30 import geario.system.WindowsHelper; 31 import core.sys.windows.wincon; 32 import std.format; 33 string msg = format("Implementation missing %s, in %s:%d", name, file, line); 34 ConsoleHelper.writeWithAttribute(msg, FOREGROUND_GREEN | FOREGROUND_RED); 35 } else { 36 assert(false, "Unsupported OS."); 37 } 38 } 39 } 40 41 mixin template BasicExceptionCtors() { 42 this(size_t line = __LINE__, string file = __FILE__) @nogc @safe pure nothrow { 43 super("", file, line, null); 44 } 45 46 this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @nogc @safe pure nothrow { 47 super(msg, file, line, next); 48 } 49 50 this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) @nogc @safe pure nothrow { 51 super(msg, file, line, next); 52 } 53 54 this(Throwable next, string file = __FILE__, size_t line = __LINE__) @nogc @safe pure nothrow { 55 assert(next !is null); 56 super(next.msg, file, line, next); 57 } 58 59 // mixin basicExceptionCtors; 60 } 61 62 class ClassNotFoundException : Exception { 63 mixin BasicExceptionCtors; 64 } 65 66 class NotImplementedException : Exception { 67 mixin BasicExceptionCtors; 68 } 69 70 class NotSupportedException : Exception { 71 mixin BasicExceptionCtors; 72 } 73 74 class IllegalArgumentException : Exception { 75 mixin BasicExceptionCtors; 76 } 77 78 /** 79 * 80 */ 81 class RuntimeException : Exception { 82 this(Throwable ex) { 83 super(ex.msg, ex); 84 } 85 86 /++ 87 Params: 88 msg = The message for the exception. 89 file = The file where the exception occurred. 90 line = The line number where the exception occurred. 91 next = The previous exception in the chain of exceptions, if any. 92 +/ 93 this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @nogc @safe pure nothrow { 94 super(msg, file, line, next); 95 } 96 97 /++ 98 Params: 99 msg = The message for the exception. 100 next = The previous exception in the chain of exceptions. 101 file = The file where the exception occurred. 102 line = The line number where the exception occurred. 103 +/ 104 this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) @nogc @safe pure nothrow { 105 super(msg, file, line, next); 106 } 107 // mixin BasicExceptionCtors; 108 } 109 110 class ExecutionException : Exception { 111 mixin BasicExceptionCtors; 112 } 113 114 class InterruptedException : Exception { 115 mixin BasicExceptionCtors; 116 } 117 118 class ParseException : Exception { 119 mixin BasicExceptionCtors; 120 } 121 122 class CloneNotSupportedException : Exception { 123 mixin BasicExceptionCtors; 124 } 125 126 class TimeoutException : Exception { 127 mixin BasicExceptionCtors; 128 } 129 130 class FileNotFoundException : Exception { 131 mixin BasicExceptionCtors; 132 } 133 134 class IOException : Exception { 135 mixin BasicExceptionCtors; 136 } 137 138 class CharacterCodingException : IOException { 139 mixin BasicExceptionCtors; 140 } 141 142 class ClosedChannelException : IOException { 143 mixin BasicExceptionCtors; 144 } 145 146 class MalformedURLException : IOException { 147 mixin BasicExceptionCtors; 148 } 149 150 class InterruptedIOException : IOException { 151 mixin BasicExceptionCtors; 152 } 153 154 class RemoteException : IOException { 155 mixin BasicExceptionCtors; 156 } 157 158 class UnsupportedEncodingException : IOException { 159 mixin BasicExceptionCtors; 160 } 161 162 class AsynchronousCloseException : ClosedChannelException { 163 mixin BasicExceptionCtors; 164 } 165 166 class CommonRuntimeException : RuntimeException { 167 mixin BasicExceptionCtors; 168 } 169 170 class IndexOutOfBoundsException : RuntimeException { 171 mixin BasicExceptionCtors; 172 } 173 174 class NegativeArraySizeException : RuntimeException { 175 mixin BasicExceptionCtors; 176 } 177 178 class ReadOnlyBufferException : RuntimeException { 179 mixin BasicExceptionCtors; 180 } 181 182 class BufferUnderflowException : RuntimeException { 183 mixin BasicExceptionCtors; 184 } 185 186 class BufferOverflowException : RuntimeException { 187 mixin BasicExceptionCtors; 188 } 189 190 class UnsupportedOperationException : RuntimeException { 191 mixin BasicExceptionCtors; 192 } 193 194 class NoSuchElementException : RuntimeException { 195 mixin BasicExceptionCtors; 196 } 197 198 class NumberFormatException : IllegalArgumentException { 199 mixin BasicExceptionCtors; 200 } 201 202 class NullPointerException : RuntimeException { 203 mixin BasicExceptionCtors; 204 } 205 206 class EofException : RuntimeException { 207 mixin BasicExceptionCtors; 208 } 209 210 class SecureNetException : RuntimeException { 211 mixin BasicExceptionCtors; 212 } 213 214 class ArithmeticException : RuntimeException { 215 mixin BasicExceptionCtors; 216 } 217 218 class IllegalStateException : Exception { 219 mixin BasicExceptionCtors; 220 } 221 222 class InvalidMarkException : IllegalStateException { 223 mixin BasicExceptionCtors; 224 } 225 226 class WritePendingException : IllegalStateException { 227 mixin BasicExceptionCtors; 228 } 229 230 class CancellationException : IllegalStateException { 231 mixin BasicExceptionCtors; 232 } 233 234 class GeneralSecurityException : Exception { 235 mixin BasicExceptionCtors; 236 } 237 238 class CertificateException : GeneralSecurityException { 239 mixin BasicExceptionCtors; 240 } 241 242 class NoSuchAlgorithmException : GeneralSecurityException { 243 mixin BasicExceptionCtors; 244 } 245 246 class ConcurrentModificationException : RuntimeException { 247 mixin BasicExceptionCtors; 248 } 249 250 class InternalError : Exception { 251 mixin BasicExceptionCtors; 252 } 253 254 class CRLException : GeneralSecurityException { 255 mixin BasicExceptionCtors; 256 } 257 258 class NoSuchProviderException : Exception { 259 mixin BasicExceptionCtors; 260 } 261 262 class CertificateNotYetValidException : Exception { 263 mixin BasicExceptionCtors; 264 } 265 266 class CertificateExpiredException : Exception { 267 mixin BasicExceptionCtors; 268 } 269 270 class SignatureException : Exception { 271 mixin BasicExceptionCtors; 272 } 273 274 class CertificateEncodingException : Exception { 275 mixin BasicExceptionCtors; 276 } 277 278 class ParsingException : Exception { 279 mixin BasicExceptionCtors; 280 } 281 282 class CertificateParsingException : ParsingException { 283 mixin BasicExceptionCtors; 284 } 285 286 class InvalidKeyException : Exception { 287 mixin BasicExceptionCtors; 288 } 289 290 class KeyStoreException : Exception { 291 mixin BasicExceptionCtors; 292 } 293 294 class UnrecoverableKeyException : Exception { 295 mixin BasicExceptionCtors; 296 } 297 298 class KeyManagementException : Exception { 299 mixin BasicExceptionCtors; 300 } 301 302 class IllegalThreadStateException : IllegalArgumentException { 303 mixin BasicExceptionCtors; 304 } 305 306 class IllegalMonitorStateException : RuntimeException { 307 mixin BasicExceptionCtors; 308 } 309 310 class NestedRuntimeException : Exception { 311 mixin BasicExceptionCtors; 312 } 313 314 class InvalidClassException : Exception { 315 mixin BasicExceptionCtors; 316 } 317 318 class InvalidObjectException : Exception { 319 mixin BasicExceptionCtors; 320 } 321 322 class ClassCastException : Exception { 323 mixin BasicExceptionCtors; 324 } 325 326 class SystemException : Exception { 327 mixin BasicExceptionCtors; 328 } 329 330 class ConfigurationException : Exception { 331 mixin BasicExceptionCtors; 332 } 333 334 335 // ===================== Error ===================== 336 337 class AssertionError : Error { 338 mixin BasicExceptionCtors; 339 } 340 341 class LinkageError : Error { 342 mixin BasicExceptionCtors; 343 } 344 345 class OutOfMemoryError : Error { 346 mixin BasicExceptionCtors; 347 } 348 349 class ThreadDeath : Error { 350 mixin BasicExceptionCtors; 351 }