PageRenderTime 46ms CodeModel.GetById 38ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/core/exception.d

http://github.com/wilkie/djehuty
D | 115 lines | 56 code | 14 blank | 45 comment | 0 complexity | 03a912e7b834dab8ed78bac6df35a5d1 MD5 | raw file
  1/*
  2 * exception.d
  3 *
  4 * This module defines common exceptions.
  5 *
  6 * Author: Dave Wilkinson
  7 * Originated: August 20th, 2009
  8 *
  9 */
 10
 11module core.exception;
 12
 13import core.string;
 14import core.definitions;
 15/*
 16class Exception {
 17	this(string msg, string file = "", ulong line = 0) {
 18		_msg = msg.dup;
 19		_file = file.dup;
 20		_line = line;
 21	}
 22
 23	string name() {
 24		return this.classinfo.name.dup;
 25	}
 26
 27	string message() {
 28		return _msg.dup;
 29	}
 30
 31	string file() {
 32		return _file;
 33	}
 34
 35	ulong line() {
 36		return _line;
 37	}
 38
 39	string toString() {
 40		return this.name() ~ " caught at " ~ _file ~ "@" ~ toStr(_line) ~ ": " ~ _msg;
 41	}
 42
 43private:
 44	char[] _msg;
 45	char[] _file;
 46	ulong _line;
 47}
 48*/
 49
 50// Exceptions for IO
 51abstract class IOException : Exception {
 52	this(string msg) {
 53		super(msg);
 54	}
 55
 56static:
 57
 58	class CreationFailure : IOException {
 59		this(string filename) {
 60			super(filename ~ " could not be created.");
 61		}
 62	}
 63
 64	class ExistenceFailure : IOException {
 65		this(string filename) {
 66			super(filename ~ " not found.");
 67		}
 68	}
 69
 70	class PermissionFailure : IOException {
 71		this(string filename) {
 72			super(filename ~ " has the wrong permissions for the operation.");
 73		}
 74	}
 75}
 76
 77// Exceptions for data structures
 78abstract class DataException : Exception {
 79	this(string msg) {
 80		super(msg);
 81	}
 82
 83static:
 84
 85	class OutOfElements : DataException {
 86		this(string objectName) {
 87			super("Out of items in " ~ objectName);
 88		}
 89	}
 90
 91	class OutOfBounds : DataException {
 92		this(string objectName) {
 93			super("Index out of bounds in " ~ objectName);
 94		}
 95	}
 96
 97	class ElementNotFound : DataException {
 98		this(string objectName) {
 99			super("Element does not exist in " ~ objectName);
100		}
101	}
102}
103
104abstract class MemoryException : Exception {
105	this(string msg) {
106		super(msg);
107	}
108
109static:
110	class OutOfMemory : MemoryException {
111		this() {
112			super("Out of memory");
113		}
114	}
115}