Mercurial > projects > dwt-win
annotate dwt/DWTError.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.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 { | |
47 /** | |
48 * The DWT error code, one of DWT.ERROR_*. | |
49 */ | |
50 public int code; | |
51 | |
52 /** | |
53 * The underlying throwable that caused the problem, | |
54 * or null if this information is not available. | |
55 */ | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
56 public Exception throwable( Exception e ){ |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
57 this.next = e; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
58 return this.next; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
59 } |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
60 public Exception throwable(){ |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
61 return this.next; |
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
62 } |
0 | 63 |
64 //static final long serialVersionUID = 3833467327105808433L; | |
65 | |
66 /** | |
67 * Constructs a new instance of this class with its | |
68 * stack trace filled in. The error code is set to an | |
69 * unspecified value. | |
70 */ | |
71 public this () { | |
72 this (DWT.ERROR_UNSPECIFIED); | |
73 } | |
74 | |
75 /** | |
76 * Constructs a new instance of this class with its | |
77 * stack trace and message filled in. The error code is | |
78 * set to an unspecified value. Specifying <code>null</code> | |
79 * as the message is equivalent to specifying an empty string. | |
80 * | |
81 * @param message the detail message for the exception | |
82 */ | |
4
bf9fe45b4422
C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
83 public this (char[] message) { |
0 | 84 this (DWT.ERROR_UNSPECIFIED, message); |
85 } | |
86 | |
87 /** | |
88 * Constructs a new instance of this class with its | |
89 * stack trace and error code filled in. | |
90 * | |
91 * @param code the DWT error code | |
92 */ | |
93 public this (int code) { | |
94 this (code, DWT.findErrorText (code)); | |
95 } | |
96 | |
97 /** | |
98 * Constructs a new instance of this class with its | |
99 * stack trace, error code and message filled in. | |
100 * Specifying <code>null</code> as the message is | |
101 * equivalent to specifying an empty string. | |
102 * | |
103 * @param code the DWT error code | |
104 * @param message the detail message for the exception | |
105 */ | |
106 public this (int code, char[] message) { | |
107 super (message); | |
108 this.code = code; | |
109 } | |
110 | |
111 /** | |
112 * Returns the underlying throwable that caused the problem, | |
113 * or null if this information is not available. | |
114 * <p> | |
115 * NOTE: This method overrides Throwable.getCause() that was | |
116 * added to JDK1.4. It is necessary to override this method | |
117 * in order for inherited printStackTrace() methods to work. | |
118 * </p> | |
119 * @return the underlying throwable | |
120 * | |
121 * @since 3.1 | |
122 */ | |
123 public Exception getCause() { | |
124 return throwable; | |
125 } | |
126 | |
127 /** | |
128 * Returns the string describing this DWTError object. | |
129 * <p> | |
130 * It is combined with the message string of the Throwable | |
131 * which caused this DWTError (if this information is available). | |
132 * </p> | |
133 * @return the error message string of this DWTError object | |
134 */ | |
135 public char[] getMessage () { | |
136 if (throwable is null) | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
137 return super.toString(); |
0 | 138 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
139 } | |
140 | |
141 /** | |
142 * Outputs a printable representation of this error's | |
143 * stack trace on the standard error stream. | |
144 * <p> | |
145 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
146 * are not provided in order to maintain compatibility with CLDC. | |
147 * </p> | |
148 */ | |
149 public void printStackTrace () { | |
150 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
59 | 151 foreach( msg; info ){ |
0 | 152 Stderr.formatln( "{}", msg ); |
153 } | |
154 if ( throwable !is null) { | |
155 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$ | |
59 | 156 foreach( msg; throwable.info ){ |
0 | 157 Stderr.formatln( "{}", msg ); |
158 } | |
159 } | |
206
cca980503056
sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents:
59
diff
changeset
|
160 } |
0 | 161 |
162 } |