Mercurial > projects > dwt-win
annotate dwt/DWTException.d @ 206:cca980503056
sync with dwt-linux, removed the simple.d
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 16 Apr 2008 20:36:50 +0200 |
parents | dc7db4338dbe |
children | ab60f3309436 |
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.DWTException; | |
14 | |
15 import dwt.DWT; | |
16 | |
17 import tango.core.Exception; | |
18 import tango.io.Stdout; | |
19 | |
20 /** | |
21 * This runtime exception is thrown whenever a recoverable 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 * exception that caused the problem (if this information is | |
26 * available (i.e. it may be null)). | |
27 * <p> | |
28 * SWTExceptions are thrown when something fails internally, | |
29 * but DWT is left in a known stable state (eg. a widget call | |
30 * was made from a non-u/i thread, or there is failure while | |
31 * reading an Image because the source file was corrupt). | |
32 * </p> | |
33 * | |
34 * @see DWTError | |
35 */ | |
36 | |
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
|
37 public class DWTException : Exception { |
0 | 38 /** |
39 * The DWT error code, one of DWT.ERROR_*. | |
40 */ | |
41 public int code; | |
42 | |
43 /** | |
44 * The underlying throwable that caused the problem, | |
45 * or null if this information is not available. | |
46 */ | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
47 public Exception throwable( Exception e ){ |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
48 this.next = e; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
49 return this.next; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
50 } |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
51 public Exception throwable(){ |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
52 return this.next; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
53 } |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
54 |
0 | 55 |
56 //static final long serialVersionUID = 3257282552304842547L; | |
57 | |
58 /** | |
59 * Constructs a new instance of this class with its | |
60 * stack trace filled in. The error code is set to an | |
61 * unspecified value. | |
62 */ | |
63 public this () { | |
64 this (DWT.ERROR_UNSPECIFIED); | |
65 } | |
66 | |
67 /** | |
68 * Constructs a new instance of this class with its | |
69 * stack trace and message filled in. The error code is | |
70 * set to an unspecified value. Specifying <code>null</code> | |
71 * as the message is equivalent to specifying an empty string. | |
72 * | |
73 * @param message the detail message for the exception | |
74 */ | |
75 public this (char[] message) { | |
76 this (DWT.ERROR_UNSPECIFIED, message); | |
77 } | |
78 | |
79 /** | |
80 * Constructs a new instance of this class with its | |
81 * stack trace and error code filled in. | |
82 * | |
83 * @param code the DWT error code | |
84 */ | |
85 public this (int code) { | |
86 this (code, DWT.findErrorText (code)); | |
87 } | |
88 | |
89 /** | |
90 * Constructs a new instance of this class with its | |
91 * stack trace, error code and message filled in. | |
92 * Specifying <code>null</code> as the message is | |
93 * equivalent to specifying an empty string. | |
94 * | |
95 * @param code the DWT error code | |
96 * @param message the detail message for the exception | |
97 */ | |
98 public this (int code, char[] message) { | |
99 super (message); | |
100 this.code = code; | |
101 } | |
102 | |
103 /** | |
104 * Returns the underlying throwable that caused the problem, | |
105 * or null if this information is not available. | |
106 * <p> | |
107 * NOTE: This method overrides Throwable.getCause() that was | |
108 * added to JDK1.4. It is necessary to override this method | |
109 * in order for inherited printStackTrace() methods to work. | |
110 * </p> | |
111 * @return the underlying throwable | |
112 * | |
113 * @since 3.1 | |
114 */ | |
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
|
115 public Exception getCause() { |
0 | 116 return throwable; |
117 } | |
118 | |
119 /** | |
120 * Returns the string describing this DWTException object. | |
121 * <p> | |
122 * It is combined with the message string of the Throwable | |
123 * which caused this DWTException (if this information is available). | |
124 * </p> | |
125 * @return the error message string of this DWTException object | |
126 */ | |
127 public char[] getMessage () { | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
128 if (throwable is null) return super.toString (); |
0 | 129 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
130 } | |
131 | |
132 /** | |
133 * Outputs a printable representation of this exception's | |
134 * stack trace on the standard error stream. | |
135 * <p> | |
136 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
137 * are not provided in order to maintain compatibility with CLDC. | |
138 * </p> | |
139 */ | |
140 public void printStackTrace () { | |
141 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
59 | 142 foreach( msg; info ){ |
0 | 143 Stderr.formatln( "{}", msg ); |
144 } | |
145 if ( throwable !is null) { | |
146 Stderr.formatln ("*** Stack trace of contained exception ***"); //$NON-NLS-1$ | |
59 | 147 foreach( msg; throwable.info ){ |
0 | 148 Stderr.formatln( "{}", msg ); |
149 } | |
150 } | |
151 } | |
152 | |
4
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
153 } |
0 | 154 |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
155 |