comparison mde/exception.d @ 25:2c28ee04a4ed

Some minor and some futile efforts. Played around with init functions, had problems, gave up and put them back. Removed idea for multiple init stages; it's not good for performance or simplicity. Adjusted exception messages. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 03 Apr 2008 17:26:52 +0100
parents 838577503598
children 611f7b9063c6
comparison
equal deleted inserted replaced
24:32eff0e01c05 25:2c28ee04a4ed
25 * The static string symbol 25 * The static string symbol
26 * should be overriden as below so that it ends up as something like "mde.file" or 26 * should be overriden as below so that it ends up as something like "mde.file" or
27 * "mde.pkg.file.Class" describing where the exception was thrown. (Since only methods overload 27 * "mde.pkg.file.Class" describing where the exception was thrown. (Since only methods overload
28 * correctly, symbol is made static and an overloadable method is used to access the correct symbol.) 28 * correctly, symbol is made static and an overloadable method is used to access the correct symbol.)
29 */ 29 */
30 class mdeException : Exception { 30 class mdeException : Exception {
31 static const symbol = "mde"; /// Override in derived classes to name the module where the error occured. 31 /// Override in derived classes to name the module where the error occured.
32 char[] getSymbol () { 32 char[] getSymbol () {
33 return symbol; 33 return "mde";
34 }
35 /// Prefix msg, e.g.: "mde.foo: message"
36 char[] prefixedMsg () {
37 return getSymbol() ~ ": " ~ msg;
34 } 38 }
35 this (char[] msg) { 39 this (char[] msg) {
36 super(getSymbol() ~ ": " ~ msg); 40 super(msg);
37 } 41 }
38 this () { // No supplied error message. 42 this () { // No supplied error message.
39 super(symbol); 43 super("");
40 } 44 }
41 } 45 }
42 46
43 /// Thrown when loading options fails. 47 /// Thrown when loading options fails.
44 class optionsLoadException : mdeException { 48 class optionsLoadException : mdeException {
45 // NOTE: if symbol is final, it can't be modified in the static this(), but as const it can
46 static const char[] symbol;
47 static this () { symbol = super.symbol ~ ".options"; }
48 char[] getSymbol () { 49 char[] getSymbol () {
49 return symbol; 50 return super.getSymbol ~ ".options";
50 } 51 }
51 52
52 this (char[] msg) { 53 this (char[] msg) {
53 super(msg); 54 super(msg);
54 } 55 }
55 } 56 }
56 57
57 /// Thrown when loading strings for the requested name and current locale fails. 58 /// Thrown when loading strings for the requested name and current locale fails.
58 class L10nLoadException : mdeException { 59 class L10nLoadException : mdeException {
59 // NOTE: if symbol is final, it can't be modified in the static this(), but as const it can
60 static const char[] symbol;
61 static this () { symbol = super.symbol ~ ".i18n.I18nTranslation"; }
62 char[] getSymbol () { 60 char[] getSymbol () {
63 return symbol; 61 return super.getSymbol ~ ".i18n.I18nTranslation";
64 } 62 }
65 63
66 this (char[] msg) { 64 this (char[] msg) {
67 super(msg); 65 super(msg);
68 } 66 }