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