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