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