Mercurial > projects > mde
annotate mde/exception.d @ 125:3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 06 Jan 2009 16:54:04 +0000 |
parents | f3d8c0441408 |
children | 9f035cd139c6 |
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 |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
8 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
17
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 */ |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
30 class mdeException : Exception { |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
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 |
55
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
69 /// Thrown when an image fails to load or cannot be loaded to a texture (unsupported format?). |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
70 class ImageException : mdeException { |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
71 char[] getSymbol () { |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
72 return super.getSymbol ~ ".gl.texture"; |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
73 } |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
74 this (char[] msg) { |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
75 super (msg); |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
76 } |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
77 } |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
78 |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
79 |
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
|
80 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
|
81 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
|
82 |
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 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
|
84 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
|
85 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
|
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 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
|
89 // Check message prepending works correctly. |
20
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
90 mdeException mE = new optionsLoadException(""); |
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
91 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
|
92 try { |
20
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
93 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
|
94 assert (false); |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
95 } catch (mdeException e) { |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
96 assert (e.msg == "ABC", e.msg); |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
97 assert (e.prefixedMsg == "mde: ABC", e.prefixedMsg); |
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
|
98 } |
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
|
99 |
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
|
100 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
|
101 } |
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
|
102 } |