Mercurial > projects > dwt-linux
annotate dwt/DWTError.d @ 158:de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 10 Feb 2008 04:19:19 +0100 |
parents | 5899e0b43e5d |
children | 654b7d7cc33c |
rev | line source |
---|---|
72 | 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 | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
0 | 12 *******************************************************************************/ |
71 | 13 module dwt.DWTError; |
0 | 14 |
71 | 15 import dwt.DWT; |
0 | 16 |
17 import tango.core.Exception; | |
18 import tango.io.Stdout; | |
19 | |
20 /** | |
21 * This error is thrown whenever an unrecoverable error | |
71 | 22 * occurs internally in DWT. The message text and error code |
0 | 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 | |
71 | 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 | |
0 | 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> | |
71 | 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. | |
0 | 40 * </p> |
41 * | |
71 | 42 * @see DWTException |
43 * @see DWT#error(int) | |
0 | 44 */ |
45 | |
71 | 46 public class DWTError : PlatformException { |
0 | 47 /** |
71 | 48 * The DWT error code, one of DWT.ERROR_*. |
0 | 49 */ |
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
|
50 public int code; |
0 | 51 |
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
|
52 /** |
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 * 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
|
54 * 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
|
55 */ |
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
|
56 public Exception throwable; |
0 | 57 |
58 //static final long serialVersionUID = 3833467327105808433L; | |
59 | |
60 /** | |
61 * Constructs a new instance of this class with its | |
62 * stack trace filled in. The error code is set to an | |
63 * unspecified value. | |
64 */ | |
65 public this () { | |
71 | 66 this (DWT.ERROR_UNSPECIFIED); |
0 | 67 } |
68 | |
69 /** | |
70 * Constructs a new instance of this class with its | |
71 * stack trace and message filled in. The error code is | |
72 * set to an unspecified value. Specifying <code>null</code> | |
73 * as the message is equivalent to specifying an empty string. | |
74 * | |
75 * @param message the detail message for the exception | |
76 */ | |
77 public this (char[] message) { | |
71 | 78 this (DWT.ERROR_UNSPECIFIED, message); |
0 | 79 } |
80 | |
81 /** | |
82 * Constructs a new instance of this class with its | |
83 * stack trace and error code filled in. | |
84 * | |
71 | 85 * @param code the DWT error code |
0 | 86 */ |
87 public this (int code) { | |
71 | 88 this (code, DWT.findErrorText (code)); |
0 | 89 } |
90 | |
91 /** | |
92 * Constructs a new instance of this class with its | |
93 * stack trace, error code and message filled in. | |
94 * Specifying <code>null</code> as the message is | |
95 * equivalent to specifying an empty string. | |
96 * | |
71 | 97 * @param code the DWT error code |
0 | 98 * @param message the detail message for the exception |
99 */ | |
100 public this (int code, char[] 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
|
101 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
|
102 this.code = code; |
0 | 103 } |
104 | |
105 /** | |
106 * Returns the underlying throwable that caused the problem, | |
107 * or null if this information is not available. | |
108 * <p> | |
109 * NOTE: This method overrides Throwable.getCause() that was | |
110 * added to JDK1.4. It is necessary to override this method | |
111 * in order for inherited printStackTrace() methods to work. | |
112 * </p> | |
113 * @return the underlying throwable | |
114 * | |
115 * @since 3.1 | |
116 */ | |
117 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
|
118 return throwable; |
0 | 119 } |
120 | |
121 /** | |
71 | 122 * Returns the string describing this DWTError object. |
0 | 123 * <p> |
124 * It is combined with the message string of the Throwable | |
71 | 125 * which caused this DWTError (if this information is available). |
0 | 126 * </p> |
71 | 127 * @return the error message string of this DWTError object |
0 | 128 */ |
129 public char[] 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
|
130 if (throwable is null) |
0 | 131 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
|
132 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
0 | 133 } |
134 | |
135 /** | |
136 * Outputs a printable representation of this error's | |
137 * stack trace on the standard error stream. | |
138 * <p> | |
139 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
140 * are not provided in order to maintain compatibility with CLDC. | |
141 * </p> | |
142 */ | |
143 public void printStackTrace () { | |
144 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
|
145 foreach( msg; info ){ |
0 | 146 Stderr.formatln( "{}", msg ); |
147 } | |
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
|
148 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
|
149 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
|
150 foreach( msg; throwable.info ){ |
0 | 151 Stderr.formatln( "{}", msg ); |
152 } | |
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
|
153 } |
0 | 154 } |
155 | |
156 } |