Mercurial > projects > dwt-linux
annotate dwt/SWTException.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.SWTException; |
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 runtime exception is thrown whenever a recoverable 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 * exception that caused the problem (if this information is | |
24 * available (i.e. it may be null)). | |
25 * <p> | |
26 * SWTExceptions are thrown when something fails internally, | |
27 * but SWT is left in a known stable state (eg. a widget call | |
28 * was made from a non-u/i thread, or there is failure while | |
29 * reading an Image because the source file was corrupt). | |
30 * </p> | |
31 * | |
32 * @see SWTError | |
33 */ | |
34 | |
35 public class SWTException : TracedException { | |
36 /** | |
37 * The SWT error code, one of SWT.ERROR_*. | |
38 */ | |
39 public int code; | |
40 | |
41 /** | |
42 * The underlying throwable that caused the problem, | |
43 * or null if this information is not available. | |
44 */ | |
45 public TracedException throwable; | |
46 | |
47 //static final long serialVersionUID = 3257282552304842547L; | |
48 | |
49 /** | |
50 * Constructs a new instance of this class with its | |
51 * stack trace filled in. The error code is set to an | |
52 * unspecified value. | |
53 */ | |
54 public this () { | |
55 this (SWT.ERROR_UNSPECIFIED); | |
56 } | |
57 | |
58 /** | |
59 * Constructs a new instance of this class with its | |
60 * stack trace and message filled in. The error code is | |
61 * set to an unspecified value. Specifying <code>null</code> | |
62 * as the message is equivalent to specifying an empty string. | |
63 * | |
64 * @param message the detail message for the exception | |
65 */ | |
66 public this (char[] message) { | |
67 this (SWT.ERROR_UNSPECIFIED, message); | |
68 } | |
69 | |
70 /** | |
71 * Constructs a new instance of this class with its | |
72 * stack trace and error code filled in. | |
73 * | |
74 * @param code the SWT error code | |
75 */ | |
76 public this (int code) { | |
77 this (code, SWT.findErrorText (code)); | |
78 } | |
79 | |
80 /** | |
81 * Constructs a new instance of this class with its | |
82 * stack trace, error code and message filled in. | |
83 * Specifying <code>null</code> as the message is | |
84 * equivalent to specifying an empty string. | |
85 * | |
86 * @param code the SWT error code | |
87 * @param message the detail message for the exception | |
88 */ | |
89 public this (int code, char[] message) { | |
90 super (message); | |
91 this.code = code; | |
92 } | |
93 | |
94 /** | |
95 * Returns the underlying throwable that caused the problem, | |
96 * or null if this information is not available. | |
97 * <p> | |
98 * NOTE: This method overrides Throwable.getCause() that was | |
99 * added to JDK1.4. It is necessary to override this method | |
100 * in order for inherited printStackTrace() methods to work. | |
101 * </p> | |
102 * @return the underlying throwable | |
103 * | |
104 * @since 3.1 | |
105 */ | |
106 public TracedException getCause() { | |
107 return throwable; | |
108 } | |
109 | |
110 /** | |
111 * Returns the string describing this SWTException object. | |
112 * <p> | |
113 * It is combined with the message string of the Throwable | |
114 * which caused this SWTException (if this information is available). | |
115 * </p> | |
116 * @return the error message string of this SWTException object | |
117 */ | |
118 public char[] getMessage () { | |
119 if (throwable is null) return super.toString (); | |
120 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ | |
121 } | |
122 | |
123 /** | |
124 * Outputs a printable representation of this exception's | |
125 * stack trace on the standard error stream. | |
126 * <p> | |
127 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
128 * are not provided in order to maintain compatibility with CLDC. | |
129 * </p> | |
130 */ | |
131 public void printStackTrace () { | |
132 Stderr.formatln( "stacktrace follows (if feature compiled in)" ); | |
133 foreach( msg; this ){ | |
134 Stderr.formatln( "{}", msg ); | |
135 } | |
136 if ( throwable !is null) { | |
137 Stderr.formatln ("*** Stack trace of contained exception ***"); //$NON-NLS-1$ | |
138 foreach( msg; throwable ){ | |
139 Stderr.formatln( "{}", msg ); | |
140 } | |
141 } | |
142 } | |
143 | |
144 } | |
145 | |
146 |