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 error is thrown whenever an unrecoverable 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 * throwable that caused the problem (if this information is
22 * available (i.e. it may be null)).
24 * SWTErrors are thrown when something fails internally which
25 * either leaves SWT in an unknown state (eg. the o/s call to
26 * remove an item from a list returns an error code) or when SWT
27 * is left in a known-to-be-unrecoverable state (eg. it runs out
28 * of callback resources). SWTErrors should not occur in typical
29 * programs, although "high reliability" applications should
32 * This class also provides support methods used by SWT to match
33 * error codes to the appropriate exception class (SWTError,
34 * SWTException, or IllegalArgumentException) and to provide
35 * human readable strings for SWT error codes.
40 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
43 public class SWTError extends Error {
45 * The SWT error code, one of SWT.ERROR_*.
50 * The underlying throwable that caused the problem,
51 * or null if this information is not available.
53 public Throwable throwable;
55 static final long serialVersionUID = 3833467327105808433L;
58 * Constructs a new instance of this class with its
59 * stack trace filled in. The error code is set to an
63 this (SWT.ERROR_UNSPECIFIED);
67 * Constructs a new instance of this class with its
68 * stack trace and message filled in. The error code is
69 * set to an unspecified value. Specifying <code>null</code>
70 * as the message is equivalent to specifying an empty string.
72 * @param message the detail message for the exception
74 public SWTError (String message) {
75 this (SWT.ERROR_UNSPECIFIED, message);
79 * Constructs a new instance of this class with its
80 * stack trace and error code filled in.
82 * @param code the SWT error code
84 public SWTError (int code) {
85 this (code, SWT.findErrorText (code));
89 * Constructs a new instance of this class with its
90 * stack trace, error code and message filled in.
91 * Specifying <code>null</code> as the message is
92 * equivalent to specifying an empty string.
94 * @param code the SWT error code
95 * @param message the detail message for the exception
97 public SWTError (int code, String message) {
103 * Returns the underlying throwable that caused the problem,
104 * or null if this information is not available.
106 * NOTE: This method overrides Throwable.getCause() that was
107 * added to JDK1.4. It is necessary to override this method
108 * in order for inherited printStackTrace() methods to work.
110 * @return the underlying throwable
115 public Throwable getCause() {
120 * Returns the string describing this SWTError object.
122 * It is combined with the message string of the Throwable
123 * which caused this SWTError (if this information is available).
125 * @return the error message string of this SWTError object
128 public String getMessage () {
129 if (throwable == null) return super.getMessage ();
130 return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$
134 * Outputs a printable representation of this error's
135 * stack trace on the standard error stream.
137 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
138 * are not provided in order to maintain compatibility with CLDC.
142 public void printStackTrace () {
143 super.printStackTrace ();