Mercurial > projects > dwt-win
annotate dwt/DWTError.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | cca980503056 |
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.DWTError; | |
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 error is thrown whenever an unrecoverable 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 * throwable that caused the problem (if this information is | |
27 * available (i.e. it may be null)). | |
28 * <p> | |
29 * SWTErrors are thrown when something fails internally which | |
30 * either leaves DWT in an unknown state (eg. the o/s call to | |
31 * remove an item from a list returns an error code) or when DWT | |
32 * is left in a known-to-be-unrecoverable state (eg. it runs out | |
33 * of callback resources). SWTErrors should not occur in typical | |
34 * programs, although "high reliability" applications should | |
35 * still catch them. | |
36 * </p><p> | |
37 * This class also provides support methods used by DWT to match | |
38 * error codes to the appropriate exception class (DWTError, | |
39 * DWTException, or IllegalArgumentException) and to provide | |
40 * human readable strings for DWT error codes. | |
41 * </p> | |
42 * | |
43 * @see DWTException | |
44 * @see DWT#error(int) | |
45 */ | |
46 | |
47 public class DWTError : PlatformException { | |
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 */ | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
57 public Exception throwable( Exception e ){ |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
58 this.next = e; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
59 return this.next; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
60 } |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
61 public Exception throwable(){ |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
62 return this.next; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
63 } |
0 | 64 |
65 //static final long serialVersionUID = 3833467327105808433L; | |
66 | |
67 /** | |
68 * Constructs a new instance of this class with its | |
69 * stack trace filled in. The error code is set to an | |
70 * unspecified value. | |
71 */ | |
72 public this () { | |
73 this (DWT.ERROR_UNSPECIFIED); | |
74 } | |
75 | |
76 /** | |
77 * Constructs a new instance of this class with its | |
78 * stack trace and message filled in. The error code is | |
79 * set to an unspecified value. Specifying <code>null</code> | |
80 * as the message is equivalent to specifying an empty string. | |
81 * | |
82 * @param message the detail message for the exception | |
83 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
206
diff
changeset
|
84 public this (String message) { |
0 | 85 this (DWT.ERROR_UNSPECIFIED, message); |
86 } | |
87 | |
88 /** | |
89 * Constructs a new instance of this class with its | |
90 * stack trace and error code filled in. | |
91 * | |
92 * @param code the DWT error code | |
93 */ | |
94 public this (int code) { | |
95 this (code, DWT.findErrorText (code)); | |
96 } | |
97 | |
98 /** | |
99 * Constructs a new instance of this class with its | |
100 * stack trace, error code and message filled in. | |
101 * Specifying <code>null</code> as the message is | |
102 * equivalent to specifying an empty string. | |
103 * | |
104 * @param code the DWT error code | |
105 * @param message the detail message for the exception | |
106 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
206
diff
changeset
|
107 public this (int code, String message) { |
0 | 108 super (message); |
109 this.code = code; | |
110 } | |
111 | |
112 /** | |
113 * Returns the underlying throwable that caused the problem, | |
114 * or null if this information is not available. | |
115 * <p> | |
116 * NOTE: This method overrides Throwable.getCause() that was | |
117 * added to JDK1.4. It is necessary to override this method | |
118 * in order for inherited printStackTrace() methods to work. | |
119 * </p> | |
120 * @return the underlying throwable | |
121 * | |
122 * @since 3.1 | |
123 */ | |
124 public Exception getCause() { | |
125 return throwable; | |
126 } | |
127 | |
128 /** | |
129 * Returns the string describing this DWTError object. | |
130 * <p> | |
131 * It is combined with the message string of the Throwable | |
132 * which caused this DWTError (if this information is available). | |
133 * </p> | |
134 * @return the error message string of this DWTError object | |
135 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
206
diff
changeset
|
136 public String getMessage () { |
0 | 137 if (throwable is null) |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
138 return super.toString(); |
0 | 139 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
140 } | |
141 | |
142 /** | |
143 * Outputs a printable representation of this error's | |
144 * stack trace on the standard error stream. | |
145 * <p> | |
146 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
147 * are not provided in order to maintain compatibility with CLDC. | |
148 * </p> | |
149 */ | |
150 public void printStackTrace () { | |
151 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
59 | 152 foreach( msg; info ){ |
0 | 153 Stderr.formatln( "{}", msg ); |
154 } | |
155 if ( throwable !is null) { | |
156 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$ | |
59 | 157 foreach( msg; throwable.info ){ |
0 | 158 Stderr.formatln( "{}", msg ); |
159 } | |
160 } | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
161 } |
0 | 162 |
163 } |