Mercurial > projects > dwt-mac
comparison dwt/DWTException.d @ 1:8b48be5454ce
The internal cocoa classes compile now
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Tue, 19 Aug 2008 17:35:17 +0200 |
parents | 380af2bdd8e5 |
children | 354c569b57a9 |
comparison
equal
deleted
inserted
replaced
0:380af2bdd8e5 | 1:8b48be5454ce |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | 10 * Port to the D programming language: |
11 * Port to the D Programming language: | 11 * Frank Benoit <benoit@tionex.de> |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 12 * Jacob Carlborg <jacob.carlborg@gmail.com> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwt.DWTError; | 14 module dwt.DWTException; |
15 | 15 |
16 import dwt.DWTError; | 16 import tango.io.Stdout; |
17 | |
17 import dwt.DWT; | 18 import dwt.DWT; |
19 import dwt.dwthelper.utils; | |
18 | 20 |
19 import dwt.internal.Library; | 21 alias toString getMessage; |
20 | |
21 import dwt.dwthelper.utils; | |
22 | 22 |
23 /** | 23 /** |
24 * This runtime exception is thrown whenever a recoverable error | 24 * This runtime exception is thrown whenever a recoverable error |
25 * occurs internally in DWT. The message text and error code | 25 * occurs internally in DWT. The message text and error code |
26 * provide a further description of the problem. The exception | 26 * provide a further description of the problem. The exception |
27 * has a <code>throwable</code> field which holds the underlying | 27 * has a <code>throwable</code> field which holds the underlying |
28 * exception that caused the problem (if this information is | 28 * exception that caused the problem (if this information is |
29 * available (i.e. it may be null)). | 29 * available (i.e. it may be null)). |
30 * <p> | 30 * <p> |
31 * DWTExceptions are thrown when something fails internally, | 31 * SWTExceptions are thrown when something fails internally, |
32 * but DWT is left in a known stable state (eg. a widget call | 32 * but DWT is left in a known stable state (eg. a widget call |
33 * was made from a non-u/i thread, or there is failure while | 33 * was made from a non-u/i thread, or there is failure while |
34 * reading an Image because the source file was corrupt). | 34 * reading an Image because the source file was corrupt). |
35 * </p> | 35 * </p> |
36 * | 36 * |
37 * @see DWTError | 37 * @see DWTError |
38 */ | 38 */ |
39 | 39 |
40 public class DWTException : Exception { | 40 public class DWTException : RuntimeException { |
41 /** | 41 /** |
42 * The DWT error code, one of DWT.ERROR_*. | 42 * The DWT error code, one of DWT.ERROR_*. |
43 */ | 43 */ |
44 public int code; | 44 public int code; |
45 | 45 |
46 /** | 46 /** |
47 * The underlying throwable that caused the problem, | 47 * The underlying throwable that caused the problem, |
48 * or null if this information is not available. | 48 * or null if this information is not available. |
49 */ | 49 */ |
50 public Exception throwable (Exception e) { | 50 public Throwable throwable( Exception e ){ |
51 this.next = e; | 51 this.next = e; |
52 return this.next; | 52 return this.next; |
53 } | 53 } |
54 | 54 public Throwable throwable(){ |
55 public Exception throwable () { | |
56 return this.next; | 55 return this.next; |
57 } | 56 } |
58 | 57 |
59 static final long serialVersionUID = 3257282552304842547L; | |
60 | 58 |
61 /** | 59 //static final long serialVersionUID = 3257282552304842547L; |
62 * Constructs a new instance of this class with its | 60 |
63 * stack trace filled in. The error code is set to an | 61 /** |
64 * unspecified value. | 62 * Constructs a new instance of this class with its |
65 */ | 63 * stack trace filled in. The error code is set to an |
66 public this () { | 64 * unspecified value. |
67 this(DWT.ERROR_UNSPECIFIED); | 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 */ | |
78 public this (String message) { | |
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, String 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 DWTException object. | |
124 * <p> | |
125 * It is combined with the message string of the Throwable | |
126 * which caused this DWTException (if this information is available). | |
127 * </p> | |
128 * @return the error message string of this DWTException object | |
129 */ | |
130 public String getMessage () { | |
131 if (throwable is null) return super.getMessage (); | |
132 return super.getMessage () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ | |
133 } | |
134 | |
135 /** | |
136 * Outputs a printable representation of this exception's | |
137 * stack trace on the standard error stream. | |
138 * <p> | |
139 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
140 * are not provided in order to maintain compatibility with CLDC. | |
141 * </p> | |
142 */ | |
143 public void printStackTrace () { | |
144 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
145 foreach( msg; info ){ | |
146 Stderr.formatln( "{}", msg ); | |
68 } | 147 } |
69 | 148 if ( throwable !is null) { |
70 /** | 149 Stderr.formatln ("*** Stack trace of contained exception ***"); //$NON-NLS-1$ |
71 * Constructs a new instance of this class with its | 150 foreach( msg; throwable.info ){ |
72 * stack trace and message filled in. The error code is | 151 Stderr.formatln( "{}", msg ); |
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 */ | |
78 public this (String message) { | |
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, String 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 DWTException object. | |
124 * <p> | |
125 * It is combined with the message String of the Throwable | |
126 * which caused this DWTException (if this information is available). | |
127 * </p> | |
128 * @return the error message String of this DWTException object | |
129 */ | |
130 public String getMessage () { | |
131 if (throwable is null) | |
132 return super.getMessage(); | |
133 return super.getMessage() + " (" + throwable.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ | |
134 } | |
135 | |
136 /** | |
137 * Outputs a printable representation of this exception'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 super.printStackTrace(); | |
146 if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable !is null) { | |
147 System.err.println("*** Stack trace of contained exception ***"); //$NON-NLS-1$ | |
148 throwable.printStackTrace(); | |
149 } | 152 } |
150 } | 153 } |
154 } | |
151 | 155 |
152 } | 156 } |
157 | |
158 |