root/dwt/DWTException.d

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