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