Mercurial > projects > dwt-win
annotate dwt/DWTError.d @ 57:41dbc4d9faab
Update to tango trunk -r3152. Thanks DavidLeon for the adjustment of TracedException to Exception and creating the patch.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 12:46:24 +0100 |
parents | 9a64a7781bab |
children | dc7db4338dbe |
rev | line source |
---|---|
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
1 /******************************************************************************* |
0 | 2 * Copyright (c) 2000, 2005 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwt.DWTError; | |
14 | |
15 import dwt.DWT; | |
16 | |
17 import tango.core.Exception; | |
18 import tango.io.Stdout; | |
19 | |
20 /** | |
21 * This error is thrown whenever an unrecoverable error | |
22 * occurs internally in DWT. The message text and error code | |
23 * provide a further description of the problem. The exception | |
24 * has a <code>throwable</code> field which holds the underlying | |
25 * throwable that caused the problem (if this information is | |
26 * available (i.e. it may be null)). | |
27 * <p> | |
28 * SWTErrors are thrown when something fails internally which | |
29 * either leaves DWT in an unknown state (eg. the o/s call to | |
30 * remove an item from a list returns an error code) or when DWT | |
31 * is left in a known-to-be-unrecoverable state (eg. it runs out | |
32 * of callback resources). SWTErrors should not occur in typical | |
33 * programs, although "high reliability" applications should | |
34 * still catch them. | |
35 * </p><p> | |
36 * This class also provides support methods used by DWT to match | |
37 * error codes to the appropriate exception class (DWTError, | |
38 * DWTException, or IllegalArgumentException) and to provide | |
39 * human readable strings for DWT error codes. | |
40 * </p> | |
41 * | |
42 * @see DWTException | |
43 * @see DWT#error(int) | |
44 */ | |
45 | |
46 public class DWTError : PlatformException { | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
47 |
0 | 48 /** |
49 * The DWT error code, one of DWT.ERROR_*. | |
50 */ | |
51 public int code; | |
52 | |
53 /** | |
54 * The underlying throwable that caused the problem, | |
55 * or null if this information is not available. | |
56 */ | |
57
41dbc4d9faab
Update to tango trunk -r3152. Thanks DavidLeon for the adjustment of TracedException to Exception and creating the patch.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
57 public Exception throwable; |
0 | 58 |
59 //static final long serialVersionUID = 3833467327105808433L; | |
60 | |
61 /** | |
62 * Constructs a new instance of this class with its | |
63 * stack trace filled in. The error code is set to an | |
64 * unspecified value. | |
65 */ | |
66 public this () { | |
67 this (DWT.ERROR_UNSPECIFIED); | |
68 } | |
69 | |
70 /** | |
71 * Constructs a new instance of this class with its | |
72 * stack trace and message filled in. The error code is | |
73 * set to an unspecified value. Specifying <code>null</code> | |
74 * as the message is equivalent to specifying an empty string. | |
75 * | |
76 * @param message the detail message for the exception | |
77 */ | |
4
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
78 public this (char[] message) { |
0 | 79 this (DWT.ERROR_UNSPECIFIED, message); |
80 } | |
81 | |
82 /** | |
83 * Constructs a new instance of this class with its | |
84 * stack trace and error code filled in. | |
85 * | |
86 * @param code the DWT error code | |
87 */ | |
88 public this (int code) { | |
89 this (code, DWT.findErrorText (code)); | |
90 } | |
91 | |
92 /** | |
93 * Constructs a new instance of this class with its | |
94 * stack trace, error code and message filled in. | |
95 * Specifying <code>null</code> as the message is | |
96 * equivalent to specifying an empty string. | |
97 * | |
98 * @param code the DWT error code | |
99 * @param message the detail message for the exception | |
100 */ | |
101 public this (int code, char[] message) { | |
102 super (message); | |
103 this.code = code; | |
104 } | |
105 | |
106 /** | |
107 * Returns the underlying throwable that caused the problem, | |
108 * or null if this information is not available. | |
109 * <p> | |
110 * NOTE: This method overrides Throwable.getCause() that was | |
111 * added to JDK1.4. It is necessary to override this method | |
112 * in order for inherited printStackTrace() methods to work. | |
113 * </p> | |
114 * @return the underlying throwable | |
115 * | |
116 * @since 3.1 | |
117 */ | |
118 public Exception getCause() { | |
119 return throwable; | |
120 } | |
121 | |
122 /** | |
123 * Returns the string describing this DWTError object. | |
124 * <p> | |
125 * It is combined with the message string of the Throwable | |
126 * which caused this DWTError (if this information is available). | |
127 * </p> | |
128 * @return the error message string of this DWTError object | |
129 */ | |
130 public char[] getMessage () { | |
131 if (throwable is null) | |
132 return super.toString (); | |
133 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ | |
134 } | |
135 | |
136 /** | |
137 * Outputs a printable representation of this error's | |
138 * stack trace on the standard error stream. | |
139 * <p> | |
140 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
141 * are not provided in order to maintain compatibility with CLDC. | |
142 * </p> | |
143 */ | |
144 public void printStackTrace () { | |
145 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
146 foreach( msg; this ){ | |
147 Stderr.formatln( "{}", msg ); | |
148 } | |
149 if ( throwable !is null) { | |
150 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$ | |
151 foreach( msg; throwable ){ | |
152 Stderr.formatln( "{}", msg ); | |
153 } | |
154 } | |
155 | |
156 } | |
4
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
157 } |
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
158 |
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
159 |
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
160 |