root/dwt/DWTError.d

Revision 246:fd9c62a2998e, 4.9 kB (checked in by Frank Benoit <benoit@tionex.de>, 2 months ago)

Updater SWT 3.4M7 to 3.4

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 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.DWTError;
14
15 import dwt.DWT;
16
17 import tango.core.Exception;
18 import tango.io.Stdout;
19 import dwt.dwthelper.utils;
20
21 /**
22  * This error is thrown whenever an unrecoverable error
23  * occurs internally in DWT. The message text and error code
24  * provide a further description of the problem. The exception
25  * has a <code>throwable</code> field which holds the underlying
26  * throwable that caused the problem (if this information is
27  * available (i.e. it may be null)).
28  * <p>
29  * SWTErrors are thrown when something fails internally which
30  * either leaves DWT in an unknown state (eg. the o/s call to
31  * remove an item from a list returns an error code) or when DWT
32  * is left in a known-to-be-unrecoverable state (eg. it runs out
33  * of callback resources). SWTErrors should not occur in typical
34  * programs, although "high reliability" applications should
35  * still catch them.
36  * </p><p>
37  * This class also provides support methods used by DWT to match
38  * error codes to the appropriate exception class (DWTError,
39  * DWTException, or IllegalArgumentException) and to provide
40  * human readable strings for DWT error codes.
41  * </p>
42  *
43  * @see DWTException
44  * @see DWT#error(int)
45  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
46  */
47
48 public class DWTError : PlatformException {
49     /**
50      * The DWT error code, one of DWT.ERROR_*.
51      */
52     public int code;
53
54     /**
55      * The underlying throwable that caused the problem,
56      * or null if this information is not available.
57      */
58     public Exception throwable( Exception e ){
59         this.next = e;
60         return this.next;
61     }
62     public Exception throwable(){
63         return this.next;
64     }
65
66     //static final long serialVersionUID = 3833467327105808433L;
67
68 /**
69  * Constructs a new instance of this class with its
70  * stack trace filled in. The error code is set to an
71  * unspecified value.
72  */
73 public this () {
74     this (DWT.ERROR_UNSPECIFIED);
75 }
76
77 /**
78  * Constructs a new instance of this class with its
79  * stack trace and message filled in. The error code is
80  * set to an unspecified value.  Specifying <code>null</code>
81  * as the message is equivalent to specifying an empty string.
82  *
83  * @param message the detail message for the exception
84  */
85 public this (String message) {
86     this (DWT.ERROR_UNSPECIFIED, message);
87 }
88
89 /**
90  * Constructs a new instance of this class with its
91  * stack trace and error code filled in.
92  *
93  * @param code the DWT error code
94  */
95 public this (int code) {
96     this (code, DWT.findErrorText (code));
97 }
98
99 /**
100  * Constructs a new instance of this class with its
101  * stack trace, error code and message filled in.
102  * Specifying <code>null</code> as the message is
103  * equivalent to specifying an empty string.
104  *
105  * @param code the DWT error code
106  * @param message the detail message for the exception
107  */
108 public this (int code, String message) {
109     super (message);
110     this.code = code;
111 }
112
113 /**
114  * Returns the underlying throwable that caused the problem,
115  * or null if this information is not available.
116  * <p>
117  * NOTE: This method overrides Throwable.getCause() that was
118  * added to JDK1.4. It is necessary to override this method
119  * in order for inherited printStackTrace() methods to work.
120  * </p>
121  * @return the underlying throwable
122  *
123  * @since 3.1
124  */
125 public Exception getCause() {
126     return throwable;
127 }
128
129 /**
130  *  Returns the string describing this DWTError object.
131  *  <p>
132  *  It is combined with the message string of the Throwable
133  *  which caused this DWTError (if this information is available).
134  *  </p>
135  *  @return the error message string of this DWTError object
136  */
137 public String getMessage () {
138     if (throwable is null)
139         return super.toString();
140     return super.toString () ~ " (" ~ 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 );
155     }
156     if ( throwable !is null) {
157         Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$
158         foreach( msg; throwable.info ){
159             Stderr.formatln( "{}", msg );
160         }
161     }
162 }
163
164 }
Note: See TracBrowser for help on using the browser.