Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Catching exceptions thrown by Runnable in Display.syncExec
Catching exceptions thrown by Runnable in Display.syncExec [message #681813] Thu, 09 June 2011 22:33
dloose  is currently offline dloose Friend
Messages: 5
Registered: August 2010
Junior Member
Is it possible to handle an Exception thrown in the body of a Runnable passed to Display.syncExec()? The javadoc says that syncExec throws SWTException, but I can't seem to make it.

I have a bunch of background jobs in my application, so I factored out a base class that looks like this:

public abstract class AbstractBackgroundJob<T> extends Job {
  protected IStatus run(final IProgressMonitor monitor) {
    IStatus status = null;
    try {
      final T result = doBackgroundProcessing(monitor);
      Display.getDefault().syncExec(new Runnable() {
        public void run() {
          if(shouldUpdateView()) {
            updateView(monitor, result);
          }
        }
      });
      return Status.OK_STATUS;
    }
    catch(Throwable t) {
      return new Status(IStatus.ERROR, DDMClientPlugin.PLUGIN_ID, t.getMessage(), t);
    }
  }
}
If I'm interpreting the javadoc correctly, any exceptions thrown by the shouldUpdateView() or updateView() should get wrapped in an SWTException and thrown out of syncExec (Throws: SWTException - ERROR_FAILED_EXEC - if an exception occurred when executing the runnable). That isn't the case though. Exceptions thrown from inside the Runnable are handled internally and all I get is a message printed to the console that looks like this:
!ENTRY org.eclipse.ui 4 0 2011-06-09 18:20:08.214
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.RuntimeException)
	at org.eclipse.swt.SWT.error(SWT.java:3884)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3885)
        snip
Caused by: java.lang.RuntimeException
	snip
Am I doing something wrong or did I misread the Javadoc? I don't mind putting the catch clause inside the Runnable, but it seems like I shouldn't have to.


Previous Topic:LabelProvider with image disables expansion of checkbox tree nodes
Next Topic:TrayItem title
Goto Forum:
  


Current Time: Sun Nov 29 00:01:54 GMT 2020

Powered by FUDForum. Page generated in 0.02271 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top