Mercurial > projects > mde
annotate 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 |
rev | line source |
---|---|
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
1 /* LICENSE BLOCK |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
4 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify it under the terms of |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
6 the GNU General Public License, version 2, as published by the Free Software Foundation. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
7 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
8 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
10 See the GNU General Public License for more details. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
11 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
12 You should have received a copy of the GNU General Public License along |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
13 with this program; if not, write to the Free Software Foundation, Inc., |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
15 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
16 /// Contains the base class for all mde exceptions plus some exception classes. |
0 | 17 module mde.exception; |
18 | |
19 /** Base class for all mde Exceptions. | |
20 * | |
21 * All packages should have their own base exception type extending this one, and for each package | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
22 * level a CTOR taking a message should pass the message to the super. |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
23 * A CTOR not taking a message and calling the super without a parameter may also be provided. |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
24 * |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
25 * The static string symbol |
7
b544c3a7c9ca
Some changes to exceptions and a few more debug commands.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
4
diff
changeset
|
26 * should be overriden as below so that it ends up as something like "mde.file" or |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
27 * "mde.pkg.file.Class" describing where the exception was thrown. (Since only methods overload |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
28 * correctly, symbol is made static and an overloadable method is used to access the correct symbol.) |
0 | 29 */ |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
30 class mdeException : Exception { |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
31 /// Override in derived classes to name the module where the error occured. |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
32 char[] getSymbol () { |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
33 return "mde"; |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
34 } |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
35 /// Prefix msg, e.g.: "mde.foo: message" |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
36 char[] prefixedMsg () { |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
37 return getSymbol() ~ ": " ~ msg; |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
38 } |
0 | 39 this (char[] msg) { |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
40 super(msg); |
0 | 41 } |
7
b544c3a7c9ca
Some changes to exceptions and a few more debug commands.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
4
diff
changeset
|
42 this () { // No supplied error message. |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
43 super(""); |
0 | 44 } |
45 } | |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
46 |
12
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
47 /// Thrown when loading options fails. |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
48 class optionsLoadException : mdeException { |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
49 char[] getSymbol () { |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
50 return super.getSymbol ~ ".options"; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
51 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
52 |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
53 this (char[] msg) { |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
54 super(msg); |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
55 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
56 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
57 |
12
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
58 /// Thrown when loading strings for the requested name and current locale fails. |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
59 class L10nLoadException : mdeException { |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
60 char[] getSymbol () { |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
61 return super.getSymbol ~ ".i18n.I18nTranslation"; |
12
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
62 } |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
63 |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
64 this (char[] msg) { |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
65 super(msg); |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
66 } |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
67 } |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
68 |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
69 debug (mdeUnitTest) { |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
70 import tango.util.log.Log : Log, Logger; |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
71 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
72 private Logger logger; |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
73 static this() { |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
74 logger = Log.getLogger ("mde.exception"); |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
75 } |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
76 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
77 unittest { |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
78 // Check message prepending works correctly. |
20
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
79 mdeException mE = new optionsLoadException(""); |
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
80 assert (mE.getSymbol() == "mde.options", mE.getSymbol()); |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
81 try { |
20
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
82 throw new mdeException ("ABC"); |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
83 assert (false); |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
84 } catch (Exception e) { |
20
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
85 assert (e.msg == "mde: ABC", e.msg); |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
86 } |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
87 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
88 logger.info ("Unittest complete."); |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
89 } |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
90 } |