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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
5 * which accompanies this distribution, and is available at
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
7 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
8 * Contributors:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
10 * Port to the D programming language:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
12 *******************************************************************************/
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
13 module dwt.DWTError;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
14
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
15 import dwt.DWT;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
16
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
17 import tango.core.Exception;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
18 import tango.io.Stdout;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
19
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
20 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
21 * This error is thrown whenever an unrecoverable error
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
22 * occurs internally in DWT. The message text and error code
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
23 * provide a further description of the problem. The exception
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
24 * has a <code>throwable</code> field which holds the underlying
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
25 * throwable that caused the problem (if this information is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
26 * available (i.e. it may be null)).
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
27 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
28 * SWTErrors are thrown when something fails internally which
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
29 * either leaves DWT in an unknown state (eg. the o/s call to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
30 * remove an item from a list returns an error code) or when DWT
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
31 * is left in a known-to-be-unrecoverable state (eg. it runs out
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
32 * of callback resources). SWTErrors should not occur in typical
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
33 * programs, although "high reliability" applications should
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
34 * still catch them.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
35 * </p><p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
36 * This class also provides support methods used by DWT to match
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
37 * error codes to the appropriate exception class (DWTError,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
38 * DWTException, or IllegalArgumentException) and to provide
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
39 * human readable strings for DWT error codes.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
40 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
41 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
42 * @see DWTException
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
43 * @see DWT#error(int)
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
44 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
45
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
46 public class DWTError : PlatformException {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
47 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
48 * The DWT error code, one of DWT.ERROR_*.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
49 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
50 public int code;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
51
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
52 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
53 * The underlying throwable that caused the problem,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
54 * or null if this information is not available.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
63
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
64 //static final long serialVersionUID = 3833467327105808433L;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
65
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
66 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
67 * Constructs a new instance of this class with its
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
68 * stack trace filled in. The error code is set to an
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
69 * unspecified value.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
70 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
71 public this () {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
72 this (DWT.ERROR_UNSPECIFIED);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
73 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
74
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
75 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
76 * Constructs a new instance of this class with its
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
77 * stack trace and message filled in. The error code is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
78 * set to an unspecified value. Specifying <code>null</code>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
79 * as the message is equivalent to specifying an empty string.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
80 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
81 * @param message the detail message for the exception
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
82 */
4
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents: 0
diff changeset
83 public this (char[] message) {
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
84 this (DWT.ERROR_UNSPECIFIED, message);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
85 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
86
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
87 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
88 * Constructs a new instance of this class with its
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
89 * stack trace and error code filled in.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
90 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
91 * @param code the DWT error code
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
92 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
93 public this (int code) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
94 this (code, DWT.findErrorText (code));
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
95 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
96
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
97 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
98 * Constructs a new instance of this class with its
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
99 * stack trace, error code and message filled in.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
100 * Specifying <code>null</code> as the message is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
101 * equivalent to specifying an empty string.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
102 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
103 * @param code the DWT error code
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
104 * @param message the detail message for the exception
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
105 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
106 public this (int code, char[] message) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
107 super (message);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
108 this.code = code;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
109 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
110
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
111 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
112 * Returns the underlying throwable that caused the problem,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
113 * or null if this information is not available.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
114 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
115 * NOTE: This method overrides Throwable.getCause() that was
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
116 * added to JDK1.4. It is necessary to override this method
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
117 * in order for inherited printStackTrace() methods to work.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
118 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
119 * @return the underlying throwable
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
120 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
121 * @since 3.1
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
122 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
123 public Exception getCause() {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
124 return throwable;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
125 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
126
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
127 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
128 * Returns the string describing this DWTError object.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
129 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
130 * It is combined with the message string of the Throwable
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
131 * which caused this DWTError (if this information is available).
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
132 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
133 * @return the error message string of this DWTError object
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
134 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
135 public char[] getMessage () {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
138 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
139 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
140
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
141 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
142 * Outputs a printable representation of this error's
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
143 * stack trace on the standard error stream.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
144 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
145 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
146 * are not provided in order to maintain compatibility with CLDC.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
147 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
148 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
149 public void printStackTrace () {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
150 Stderr.formatln( "stacktrace follows (if feature compiled in)" );
59
dc7db4338dbe MenuItem
Frank Benoit <benoit@tionex.de>
parents: 57
diff changeset
151 foreach( msg; info ){
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
152 Stderr.formatln( "{}", msg );
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
153 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
154 if ( throwable !is null) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
155 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$
59
dc7db4338dbe MenuItem
Frank Benoit <benoit@tionex.de>
parents: 57
diff changeset
156 foreach( msg; throwable.info ){
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
157 Stderr.formatln( "{}", msg );
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
158 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
159 }
206
cca980503056 sync with dwt-linux, removed the simple.d
Frank Benoit <benoit@tionex.de>
parents: 59
diff changeset
160 }
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
161
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
162 }