Mercurial > projects > dwt-linux
annotate dwt/SWTError.d @ 10:63c023465156
moved from org.eclipse.swt to dwt
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 05 Jan 2008 17:58:37 +0100 |
parents | ad2b69216039 |
children | 8cec8f536af3 |
rev | line source |
---|---|
0 | 1 /******************************************************************************* |
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 *******************************************************************************/ | |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
11 module dwt.SWTError; |
0 | 12 |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
13 import dwt.SWT; |
0 | 14 |
15 import tango.core.Exception; | |
16 import tango.io.Stdout; | |
17 | |
18 /** | |
19 * This error is thrown whenever an unrecoverable error | |
20 * occurs internally in SWT. The message text and error code | |
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 | |
27 * either leaves SWT in an unknown state (eg. the o/s call to | |
28 * remove an item from a list returns an error code) or when SWT | |
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> | |
34 * This class also provides support methods used by SWT to match | |
35 * error codes to the appropriate exception class (SWTError, | |
36 * SWTException, or IllegalArgumentException) and to provide | |
37 * human readable strings for SWT error codes. | |
38 * </p> | |
39 * | |
40 * @see SWTException | |
41 * @see SWT#error(int) | |
42 */ | |
43 | |
44 public class SWTError : PlatformException { | |
45 /** | |
46 * The SWT error code, one of SWT.ERROR_*. | |
47 */ | |
48 public int code; | |
49 | |
50 /** | |
51 * The underlying throwable that caused the problem, | |
52 * or null if this information is not available. | |
53 */ | |
54 public TracedException throwable; | |
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 () { | |
64 this (SWT.ERROR_UNSPECIFIED); | |
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) { | |
76 this (SWT.ERROR_UNSPECIFIED, message); | |
77 } | |
78 | |
79 /** | |
80 * Constructs a new instance of this class with its | |
81 * stack trace and error code filled in. | |
82 * | |
83 * @param code the SWT error code | |
84 */ | |
85 public this (int code) { | |
86 this (code, SWT.findErrorText (code)); | |
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 * | |
95 * @param code the SWT error code | |
96 * @param message the detail message for the exception | |
97 */ | |
98 public this (int code, char[] message) { | |
99 super (message); | |
100 this.code = code; | |
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() { | |
116 return throwable; | |
117 } | |
118 | |
119 /** | |
120 * Returns the string describing this SWTError object. | |
121 * <p> | |
122 * It is combined with the message string of the Throwable | |
123 * which caused this SWTError (if this information is available). | |
124 * </p> | |
125 * @return the error message string of this SWTError object | |
126 */ | |
127 public char[] getMessage () { | |
128 if (throwable is null) | |
129 return super.toString(); | |
130 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ | |
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 } | |
146 if ( throwable !is null) { | |
147 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$ | |
148 foreach( msg; throwable ){ | |
149 Stderr.formatln( "{}", msg ); | |
150 } | |
151 } | |
152 } | |
153 | |
154 } |