1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt;
17 * This runtime exception is thrown whenever a recoverable error
18 * occurs internally in SWT. The message text and error code
19 * provide a further description of the problem. The exception
20 * has a <code>throwable</code> field which holds the underlying
21 * exception that caused the problem (if this information is
22 * available (i.e. it may be null)).
24 * SWTExceptions are thrown when something fails internally,
25 * but SWT is left in a known stable state (eg. a widget call
26 * was made from a non-u/i thread, or there is failure while
27 * reading an Image because the source file was corrupt).
31 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
34 public class SWTException extends RuntimeException {
36 * The SWT error code, one of SWT.ERROR_*.
41 * The underlying throwable that caused the problem,
42 * or null if this information is not available.
44 public Throwable throwable;
46 static final long serialVersionUID = 3257282552304842547L;
49 * Constructs a new instance of this class with its
50 * stack trace filled in. The error code is set to an
53 public SWTException () {
54 this (SWT.ERROR_UNSPECIFIED);
58 * Constructs a new instance of this class with its
59 * stack trace and message filled in. The error code is
60 * set to an unspecified value. Specifying <code>null</code>
61 * as the message is equivalent to specifying an empty string.
63 * @param message the detail message for the exception
65 public SWTException (String message) {
66 this (SWT.ERROR_UNSPECIFIED, message);
70 * Constructs a new instance of this class with its
71 * stack trace and error code filled in.
73 * @param code the SWT error code
75 public SWTException (int code) {
76 this (code, SWT.findErrorText (code));
80 * Constructs a new instance of this class with its
81 * stack trace, error code and message filled in.
82 * Specifying <code>null</code> as the message is
83 * equivalent to specifying an empty string.
85 * @param code the SWT error code
86 * @param message the detail message for the exception
88 public SWTException (int code, String message) {
94 * Returns the underlying throwable that caused the problem,
95 * or null if this information is not available.
97 * NOTE: This method overrides Throwable.getCause() that was
98 * added to JDK1.4. It is necessary to override this method
99 * in order for inherited printStackTrace() methods to work.
101 * @return the underlying throwable
106 public Throwable getCause() {
111 * Returns the string describing this SWTException object.
113 * It is combined with the message string of the Throwable
114 * which caused this SWTException (if this information is available).
116 * @return the error message string of this SWTException object
119 public String getMessage () {
120 if (throwable == null) return super.getMessage ();
121 return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$
125 * Outputs a printable representation of this exception's
126 * stack trace on the standard error stream.
128 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
129 * are not provided in order to maintain compatibility with CLDC.
133 public void printStackTrace () {
134 super.printStackTrace ();