Top Description Fields Constructors Methods
org.eclipse.swt.internal

public Class ExceptionStash

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
org.eclipse.swt.widgets.Display

The intent of this class is to insulate SWT from exceptions occurring in user's listeners, so that SWT remains stable and does not accidentally crash JVM or enter some very broken state. The supposed use is:
void someSwtInternalFunction() {
    // Make a stash to collect all exceptions from user listeners
    try (ExceptionStash exceptions = new ExceptionStash ()) {
        // Perform some action that may call a throwing user's listener
        try {
           sendEvent(SWT.SomeEvent);
        } catch (Error | RuntimeException ex) {
            exceptions.stash (ex);
        }

        // Do some important SWT stuff that you would normally do in
        // 'finally' clause. With 'ExceptionStash' you can interleave
        // important things with listeners without making code ugly.
        MakeSureThingsDontBreak();

        // Perform another action that may call a throwing user's listener.
        // Done in an independent 'try' block to make sure that all events
        // are sent regardless of exceptions in some of the listeners.
        try {
           askWidgetToSendMoreEvents();
        } catch (Error | RuntimeException ex) {
            exceptions.stash (ex);
        }

        // Exiting from 'try' statement will close ExceptionStash and
        // re-throw collected exception. If there are multiple exceptions,
        // all subsequent ones will be added as 'Throwable.addSuppressed()'.
    }
} 

Field Summary

Modifier and TypeField and Description
pack-priv Throwable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.
public void
stash(Throwable throwable)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

storedThrowableback to summary
pack-priv Throwable storedThrowable

Constructor Detail

ExceptionStashback to summary
public ExceptionStash()

Method Detail

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

stashback to summary
public void stash(Throwable throwable)