KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > SWTException


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  *******************************************************************************/

11 package org.eclipse.swt;
12
13 import org.eclipse.swt.internal.*;
14
15 /**
16  * This runtime exception is thrown whenever a recoverable error
17  * occurs internally in SWT. The message text and error code
18  * provide a further description of the problem. The exception
19  * has a <code>throwable</code> field which holds the underlying
20  * exception that caused the problem (if this information is
21  * available (i.e. it may be null)).
22  * <p>
23  * SWTExceptions are thrown when something fails internally,
24  * but SWT is left in a known stable state (eg. a widget call
25  * was made from a non-u/i thread, or there is failure while
26  * reading an Image because the source file was corrupt).
27  * </p>
28  *
29  * @see SWTError
30  */

31
32 public class SWTException extends RuntimeException JavaDoc {
33     /**
34      * The SWT error code, one of SWT.ERROR_*.
35      */

36     public int code;
37
38     /**
39      * The underlying throwable that caused the problem,
40      * or null if this information is not available.
41      */

42     public Throwable JavaDoc throwable;
43     
44     static final long serialVersionUID = 3257282552304842547L;
45     
46 /**
47  * Constructs a new instance of this class with its
48  * stack trace filled in. The error code is set to an
49  * unspecified value.
50  */

51 public SWTException () {
52     this (SWT.ERROR_UNSPECIFIED);
53 }
54
55 /**
56  * Constructs a new instance of this class with its
57  * stack trace and message filled in. The error code is
58  * set to an unspecified value. Specifying <code>null</code>
59  * as the message is equivalent to specifying an empty string.
60  *
61  * @param message the detail message for the exception
62  */

63 public SWTException (String JavaDoc message) {
64     this (SWT.ERROR_UNSPECIFIED, message);
65 }
66
67 /**
68  * Constructs a new instance of this class with its
69  * stack trace and error code filled in.
70  *
71  * @param code the SWT error code
72  */

73 public SWTException (int code) {
74     this (code, SWT.findErrorText (code));
75 }
76
77 /**
78  * Constructs a new instance of this class with its
79  * stack trace, error code and message filled in.
80  * Specifying <code>null</code> as the message is
81  * equivalent to specifying an empty string.
82  *
83  * @param code the SWT error code
84  * @param message the detail message for the exception
85  */

86 public SWTException (int code, String JavaDoc message) {
87     super (message);
88     this.code = code;
89 }
90
91 /**
92  * Returns the underlying throwable that caused the problem,
93  * or null if this information is not available.
94  * <p>
95  * NOTE: This method overrides Throwable.getCause() that was
96  * added to JDK1.4. It is necessary to override this method
97  * in order for inherited printStackTrace() methods to work.
98  * </p>
99  * @return the underlying throwable
100  *
101  * @since 3.1
102  */

103 public Throwable JavaDoc getCause() {
104     return throwable;
105 }
106
107 /**
108  * Returns the string describing this SWTException object.
109  * <p>
110  * It is combined with the message string of the Throwable
111  * which caused this SWTException (if this information is available).
112  * </p>
113  * @return the error message string of this SWTException object
114  */

115 public String JavaDoc getMessage () {
116     if (throwable == null) return super.getMessage ();
117     return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$
118
}
119
120 /**
121  * Outputs a printable representation of this exception's
122  * stack trace on the standard error stream.
123  * <p>
124  * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
125  * are not provided in order to maintain compatibility with CLDC.
126  * </p>
127  */

128 public void printStackTrace () {
129     super.printStackTrace ();
130     if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable != null) {
131         System.err.println ("*** Stack trace of contained exception ***"); //$NON-NLS-1$
132
throwable.printStackTrace ();
133     }
134 }
135
136 }
137
138
139
Popular Tags