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