1 2 // Copyright Ferdinand Majerech 2011 - 2012. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 8 /// Exceptions thrown by D:GameVFS and exception related code. 9 module dgamevfs.exceptions; 10 11 12 import std.conv; 13 14 15 /// Parent class of all exceptions thrown at VFS errors. 16 abstract class VFSException : Exception 17 { 18 public this(string msg, string file = __FILE__, int line = __LINE__) @safe pure nothrow 19 { 20 super(msg, file, line); 21 } 22 } 23 24 /// Exception thrown when a file/directory was not found. 25 class VFSNotFoundException : VFSException 26 { 27 public this(string msg, string file = __FILE__, int line = __LINE__) @safe pure nothrow 28 { 29 super(msg, file, line); 30 } 31 } 32 33 /// Exception thrown when an invalid path or file/directory name is detected. 34 class VFSInvalidPathException : VFSException 35 { 36 public this(string msg, string file = __FILE__, int line = __LINE__) @safe pure nothrow 37 { 38 super(msg, file, line); 39 } 40 } 41 42 /// Exception thrown at input/output errors. 43 class VFSIOException : VFSException 44 { 45 public this(string msg, string file = __FILE__, int line = __LINE__) @safe pure nothrow 46 { 47 super(msg, file, line); 48 } 49 } 50 51 /// Exception thrown at mounting errors. 52 class VFSMountException : VFSException 53 { 54 public this(string msg, string file = __FILE__, int line = __LINE__) @safe pure nothrow 55 { 56 super(msg, file, line); 57 } 58 } 59 60 package: 61 62 // Template for shortcut functions to throw VFS exceptions. 63 package template error(E) if(is(E : VFSException)) 64 { 65 E error(string file = __FILE__, int line = __LINE__, A ...)(A args) @safe pure 66 { 67 string message; 68 foreach(arg; args) { message ~= to!string(arg); } 69 return new E(message, file, line); 70 } 71 } 72 73 alias error!VFSNotFoundException notFound; 74 alias error!VFSInvalidPathException invalidPath; 75 alias error!VFSIOException ioError; 76 alias error!VFSMountException mountError; 77