Mercurial > projects > dwt-linux
annotate dwt/DWTError.d @ 259:c0d810de7093
Update SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 29 Jun 2008 14:33:38 +0200 |
parents | 380bad9f6852 |
children | 4bffbf81e2d6 |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 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 | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
0 | 12 *******************************************************************************/ |
71 | 13 module dwt.DWTError; |
0 | 14 |
238 | 15 import dwt.dwthelper.utils; |
16 | |
71 | 17 import dwt.DWT; |
0 | 18 |
19 import tango.core.Exception; | |
20 import tango.io.Stdout; | |
21 | |
22 /** | |
23 * This error is thrown whenever an unrecoverable error | |
71 | 24 * occurs internally in DWT. The message text and error code |
0 | 25 * provide a further description of the problem. The exception |
26 * has a <code>throwable</code> field which holds the underlying | |
27 * throwable that caused the problem (if this information is | |
28 * available (i.e. it may be null)). | |
29 * <p> | |
30 * SWTErrors are thrown when something fails internally which | |
71 | 31 * either leaves DWT in an unknown state (eg. the o/s call to |
32 * remove an item from a list returns an error code) or when DWT | |
0 | 33 * is left in a known-to-be-unrecoverable state (eg. it runs out |
34 * of callback resources). SWTErrors should not occur in typical | |
35 * programs, although "high reliability" applications should | |
36 * still catch them. | |
37 * </p><p> | |
71 | 38 * This class also provides support methods used by DWT to match |
39 * error codes to the appropriate exception class (DWTError, | |
40 * DWTException, or IllegalArgumentException) and to provide | |
41 * human readable strings for DWT error codes. | |
0 | 42 * </p> |
43 * | |
71 | 44 * @see DWTException |
45 * @see DWT#error(int) | |
259 | 46 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
0 | 47 */ |
48 | |
71 | 49 public class DWTError : PlatformException { |
0 | 50 /** |
71 | 51 * The DWT error code, one of DWT.ERROR_*. |
0 | 52 */ |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
53 public int code; |
0 | 54 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
55 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
56 * The underlying throwable that caused the problem, |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
57 * or null if this information is not available. |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
58 */ |
231
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
59 public Exception throwable( Exception e ){ |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
60 this.next = e; |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
61 return this.next; |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
62 } |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
63 public Exception throwable(){ |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
64 return this.next; |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
65 } |
0 | 66 |
67 //static final long serialVersionUID = 3833467327105808433L; | |
68 | |
69 /** | |
70 * Constructs a new instance of this class with its | |
71 * stack trace filled in. The error code is set to an | |
72 * unspecified value. | |
73 */ | |
74 public this () { | |
71 | 75 this (DWT.ERROR_UNSPECIFIED); |
0 | 76 } |
77 | |
78 /** | |
79 * Constructs a new instance of this class with its | |
80 * stack trace and message filled in. The error code is | |
81 * set to an unspecified value. Specifying <code>null</code> | |
82 * as the message is equivalent to specifying an empty string. | |
83 * | |
84 * @param message the detail message for the exception | |
85 */ | |
238 | 86 public this (String message) { |
71 | 87 this (DWT.ERROR_UNSPECIFIED, message); |
0 | 88 } |
89 | |
90 /** | |
91 * Constructs a new instance of this class with its | |
92 * stack trace and error code filled in. | |
93 * | |
71 | 94 * @param code the DWT error code |
0 | 95 */ |
96 public this (int code) { | |
71 | 97 this (code, DWT.findErrorText (code)); |
0 | 98 } |
99 | |
100 /** | |
101 * Constructs a new instance of this class with its | |
102 * stack trace, error code and message filled in. | |
103 * Specifying <code>null</code> as the message is | |
104 * equivalent to specifying an empty string. | |
105 * | |
71 | 106 * @param code the DWT error code |
0 | 107 * @param message the detail message for the exception |
108 */ | |
238 | 109 public this (int code, String message) { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
110 super (message); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
111 this.code = code; |
0 | 112 } |
113 | |
114 /** | |
115 * Returns the underlying throwable that caused the problem, | |
116 * or null if this information is not available. | |
117 * <p> | |
118 * NOTE: This method overrides Throwable.getCause() that was | |
119 * added to JDK1.4. It is necessary to override this method | |
120 * in order for inherited printStackTrace() methods to work. | |
121 * </p> | |
122 * @return the underlying throwable | |
123 * | |
124 * @since 3.1 | |
125 */ | |
126 public Exception getCause() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
127 return throwable; |
0 | 128 } |
129 | |
130 /** | |
71 | 131 * Returns the string describing this DWTError object. |
0 | 132 * <p> |
133 * It is combined with the message string of the Throwable | |
71 | 134 * which caused this DWTError (if this information is available). |
0 | 135 * </p> |
71 | 136 * @return the error message string of this DWTError object |
0 | 137 */ |
238 | 138 public String getMessage () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
139 if (throwable is null) |
0 | 140 return super.toString(); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
141 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
0 | 142 } |
143 | |
144 /** | |
145 * Outputs a printable representation of this error's | |
146 * stack trace on the standard error stream. | |
147 * <p> | |
148 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
149 * are not provided in order to maintain compatibility with CLDC. | |
150 * </p> | |
151 */ | |
152 public void printStackTrace () { | |
153 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
154 foreach( msg; info ){ |
0 | 155 Stderr.formatln( "{}", msg ); |
156 } | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
157 if ( throwable !is null) { |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
158 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
159 foreach( msg; throwable.info ){ |
0 | 160 Stderr.formatln( "{}", msg ); |
161 } | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
162 } |
0 | 163 } |
164 | |
165 } |