comparison dwt/DWTError.d @ 1:8b48be5454ce

The internal cocoa classes compile now
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 19 Aug 2008 17:35:17 +0200
parents 380af2bdd8e5
children 354c569b57a9
comparison
equal deleted inserted replaced
0:380af2bdd8e5 1:8b48be5454ce
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * 10 * Port to the D programming language:
11 * Port to the D Programming language: 11 * Frank Benoit <benoit@tionex.de>
12 * Jacob Carlborg <jacob.carlborg@gmail.com> 12 * Jacob Carlborg <jacob.carlborg@gmail.com>
13 *******************************************************************************/ 13 *******************************************************************************/
14 module dwt.DWTError; 14 module dwt.DWTError;
15 15
16 import tango.core.Exception; 16 import tango.io.Stdout;
17 17
18 import dwt.internal.Library;
19 import dwt.DWT; 18 import dwt.DWT;
19 import dwt.dwthelper.utils;
20 20
21 import dwt.dwthelper.utils; 21 alias toString getMessage;
22 22
23 /** 23 /**
24 * This error is thrown whenever an unrecoverable error 24 * This error is thrown whenever an unrecoverable error
25 * occurs internally in DWT. The message text and error code 25 * occurs internally in DWT. The message text and error code
26 * provide a further description of the problem. The exception 26 * provide a further description of the problem. The exception
27 * has a <code>throwable</code> field which holds the underlying 27 * has a <code>throwable</code> field which holds the underlying
28 * throwable that caused the problem (if this information is 28 * throwable that caused the problem (if this information is
29 * available (i.e. it may be null)). 29 * available (i.e. it may be null)).
30 * <p> 30 * <p>
31 * DWTErrors are thrown when something fails internally which 31 * SWTErrors are thrown when something fails internally which
32 * either leaves DWT in an unknown state (eg. the o/s call to 32 * either leaves DWT in an unknown state (eg. the o/s call to
33 * remove an item from a list returns an error code) or when DWT 33 * remove an item from a list returns an error code) or when DWT
34 * is left in a known-to-be-unrecoverable state (eg. it runs out 34 * is left in a known-to-be-unrecoverable state (eg. it runs out
35 * of callback resources). DWTErrors should not occur in typical 35 * of callback resources). SWTErrors should not occur in typical
36 * programs, although "high reliability" applications should 36 * programs, although "high reliability" applications should
37 * still catch them. 37 * still catch them.
38 * </p><p> 38 * </p><p>
39 * This class also provides support methods used by DWT to match 39 * This class also provides support methods used by DWT to match
40 * error codes to the appropriate exception class (DWTError, 40 * error codes to the appropriate exception class (DWTError,
41 * DWTException, or IllegalArgumentException) and to provide 41 * DWTException, or IllegalArgumentException) and to provide
42 * human readable Strings for DWT error codes. 42 * human readable strings for DWT error codes.
43 * </p> 43 * </p>
44 * 44 *
45 * @see DWTException 45 * @see DWTException
46 * @see DWT#error(int) 46 * @see DWT#error(int)
47 */ 47 */
48 48
49 public class DWTError : PlatformException { 49 public class DWTError : Error {
50 /** 50 /**
51 * The DWT error code, one of DWT.ERROR_*. 51 * The DWT error code, one of DWT.ERROR_*.
52 */ 52 */
53 public int code; 53 public int code;
54 54
55 /** 55 /**
56 * The underlying throwable that caused the problem, 56 * The underlying throwable that caused the problem,
57 * or null if this information is not available. 57 * or null if this information is not available.
58 */ 58 */
59 public Exception throwable (Exception e) { 59 public Throwable throwable( Exception e ){
60 this.next = e; 60 this.next = e;
61 return this.next; 61 return this.next;
62 } 62 }
63 63 public Throwable throwable(){
64 public Exception throwable () {
65 return this.next; 64 return this.next;
66 } 65 }
67 66
68 static final long serialVersionUID = 3833467327105808433L; 67 //static final long serialVersionUID = 3833467327105808433L;
69 68
70 /** 69 /**
71 * Constructs a new instance of this class with its 70 * Constructs a new instance of this class with its
72 * stack trace filled in. The error code is set to an 71 * stack trace filled in. The error code is set to an
73 * unspecified value. 72 * unspecified value.
74 */ 73 */
75 public this () { 74 public this () {
76 this(DWT.ERROR_UNSPECIFIED); 75 this (DWT.ERROR_UNSPECIFIED);
76 }
77
78 /**
79 * Constructs a new instance of this class with its
80 * stack trace and message filled in. The error code is
81 * set to an unspecified value. Specifying <code>null</code>
82 * as the message is equivalent to specifying an empty string.
83 *
84 * @param message the detail message for the exception
85 */
86 public this (String message) {
87 this (DWT.ERROR_UNSPECIFIED, message);
88 }
89
90 /**
91 * Constructs a new instance of this class with its
92 * stack trace and error code filled in.
93 *
94 * @param code the DWT error code
95 */
96 public this (int code) {
97 this (code, DWT.findErrorText (code));
98 }
99
100 /**
101 * Constructs a new instance of this class with its
102 * stack trace, error code and message filled in.
103 * Specifying <code>null</code> as the message is
104 * equivalent to specifying an empty string.
105 *
106 * @param code the DWT error code
107 * @param message the detail message for the exception
108 */
109 public this (int code, String message) {
110 super (message);
111 this.code = code;
112 }
113
114 /**
115 * Returns the underlying throwable that caused the problem,
116 * or null if this information is not available.
117 * <p>
118 * NOTE: This method overrides Throwable.getCause() that was
119 * added to JDK1.4. It is necessary to override this method
120 * in order for inherited printStackTrace() methods to work.
121 * </p>
122 * @return the underlying throwable
123 *
124 * @since 3.1
125 */
126 public Throwable getCause() {
127 return throwable;
128 }
129
130 /**
131 * Returns the string describing this DWTError object.
132 * <p>
133 * It is combined with the message string of the Throwable
134 * which caused this DWTError (if this information is available).
135 * </p>
136 * @return the error message string of this DWTError object
137 */
138 public String getMessage () {
139 if (throwable is null) return super.getMessage();
140 return super.getMessage () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$
141 }
142
143 /**
144 * Outputs a printable representation of this error's
145 * stack trace on the standard error stream.
146 * <p>
147 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
148 * are not provided in order to maintain compatibility with CLDC.
149 * </p>
150 */
151 public void printStackTrace () {
152 Stderr.formatln( "stacktrace follows (if feature compiled in)" );
153 foreach( msg; info ){
154 Stderr.formatln( "{}", msg );
77 } 155 }
78 156 if ( throwable !is null) {
79 /** 157 Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$
80 * Constructs a new instance of this class with its 158 foreach( msg; throwable.info ){
81 * stack trace and message filled in. The error code is 159 Stderr.formatln( "{}", msg );
82 * set to an unspecified value. Specifying <code>null</code>
83 * as the message is equivalent to specifying an empty String.
84 *
85 * @param message the detail message for the exception
86 */
87 public this (String message) {
88 this(DWT.ERROR_UNSPECIFIED, message);
89 }
90
91 /**
92 * Constructs a new instance of this class with its
93 * stack trace and error code filled in.
94 *
95 * @param code the DWT error code
96 */
97 public this (int code) {
98 this(code, DWT.findErrorText(code));
99 }
100
101 /**
102 * Constructs a new instance of this class with its
103 * stack trace, error code and message filled in.
104 * Specifying <code>null</code> as the message is
105 * equivalent to specifying an empty String.
106 *
107 * @param code the DWT error code
108 * @param message the detail message for the exception
109 */
110 public this (int code, String message) {
111 super(message);
112 this.code = code;
113 }
114
115 /**
116 * Returns the underlying throwable that caused the problem,
117 * or null if this information is not available.
118 * <p>
119 * NOTE: This method overrides Throwable.getCause() that was
120 * added to JDK1.4. It is necessary to override this method
121 * in order for inherited printStackTrace() methods to work.
122 * </p>
123 * @return the underlying throwable
124 *
125 * @since 3.1
126 */
127 public Exception getCause () {
128 return throwable;
129 }
130
131 /**
132 * Returns the String describing this DWTError object.
133 * <p>
134 * It is combined with the message String of the Throwable
135 * which caused this DWTError (if this information is available).
136 * </p>
137 * @return the error message String of this DWTError object
138 */
139 public String getMessage () {
140 if (throwable is null)
141 return super.getMessage();
142 return super.getMessage() + " (" + throwable.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
143 }
144
145 /**
146 * Outputs a printable representation of this error's
147 * stack trace on the standard error stream.
148 * <p>
149 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
150 * are not provided in order to maintain compatibility with CLDC.
151 * </p>
152 */
153 public void printStackTrace () {
154 super.printStackTrace();
155 if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable !is null) {
156 System.err.println("*** Stack trace of contained error ***"); //$NON-NLS-1$
157 throwable.printStackTrace();
158 } 160 }
159 } 161 }
162 }
160 163
161 } 164 }