KickJava   Java API By Example, From Geeks To Geeks.

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


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 error is thrown whenever an unrecoverable 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  * throwable that caused the problem (if this information is
21  * available (i.e. it may be null)).
22  * <p>
23  * SWTErrors are thrown when something fails internally which
24  * either leaves SWT in an unknown state (eg. the o/s call to
25  * remove an item from a list returns an error code) or when SWT
26  * is left in a known-to-be-unrecoverable state (eg. it runs out
27  * of callback resources). SWTErrors should not occur in typical
28  * programs, although "high reliability" applications should
29  * still catch them.
30  * </p><p>
31  * This class also provides support methods used by SWT to match
32  * error codes to the appropriate exception class (SWTError,
33  * SWTException, or IllegalArgumentException) and to provide
34  * human readable strings for SWT error codes.
35  * </p>
36  *
37  * @see SWTException
38  * @see SWT#error(int)
39  */

40
41 public class SWTError extends Error JavaDoc {
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 JavaDoc throwable;
52
53     static final long serialVersionUID = 3833467327105808433L;
54     
55 /**
56  * Constructs a new instance of this class with its
57  * stack trace filled in. The error code is set to an
58  * unspecified value.
59  */

60 public SWTError () {
61     this (SWT.ERROR_UNSPECIFIED);
62 }
63
64 /**
65  * Constructs a new instance of this class with its
66  * stack trace and message filled in. The error code is
67  * set to an unspecified value. Specifying <code>null</code>
68  * as the message is equivalent to specifying an empty string.
69  *
70  * @param message the detail message for the exception
71  */

72 public SWTError (String JavaDoc message) {
73     this (SWT.ERROR_UNSPECIFIED, message);
74 }
75
76 /**
77  * Constructs a new instance of this class with its
78  * stack trace and error code filled in.
79  *
80  * @param code the SWT error code
81  */

82 public SWTError (int code) {
83     this (code, SWT.findErrorText (code));
84 }
85
86 /**
87  * Constructs a new instance of this class with its
88  * stack trace, error code and message filled in.
89  * Specifying <code>null</code> as the message is
90  * equivalent to specifying an empty string.
91  *
92  * @param code the SWT error code
93  * @param message the detail message for the exception
94  */

95 public SWTError (int code, String JavaDoc message) {
96     super (message);
97     this.code = code;
98 }
99
100 /**
101  * Returns the underlying throwable that caused the problem,
102  * or null if this information is not available.
103  * <p>
104  * NOTE: This method overrides Throwable.getCause() that was
105  * added to JDK1.4. It is necessary to override this method
106  * in order for inherited printStackTrace() methods to work.
107  * </p>
108  * @return the underlying throwable
109  *
110  * @since 3.1
111  */

112 public Throwable JavaDoc getCause() {
113     return throwable;
114 }
115
116 /**
117  * Returns the string describing this SWTError object.
118  * <p>
119  * It is combined with the message string of the Throwable
120  * which caused this SWTError (if this information is available).
121  * </p>
122  * @return the error message string of this SWTError object
123  */

124 public String JavaDoc getMessage () {
125     if (throwable == null) return super.getMessage ();
126     return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$
127
}
128
129 /**
130  * Outputs a printable representation of this error's
131  * stack trace on the standard error stream.
132  * <p>
133  * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
134  * are not provided in order to maintain compatibility with CLDC.
135  * </p>
136  */

137 public void printStackTrace () {
138     super.printStackTrace ();
139     if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable != null) {
140         System.err.println ("*** Stack trace of contained error ***"); //$NON-NLS-1$
141
throwable.printStackTrace ();
142     }
143 }
144
145 }
146
Popular Tags