Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to shutdown on error
How to shutdown on error [message #488508] Mon, 28 September 2009 21:28 Go to next message
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
If one of my bundles fail to initialize properly, I'd like to show an error dialog and shut down the RCP application gracefully.

Calling getWorkbench().close() results in "java.lang.IllegalStateException: Workbench has not been created yet." Is there another option (other than System.exit(1))?
Re: How to shutdown on error [message #488812 is a reply to message #488508] Wed, 30 September 2009 06:55 Go to previous messageGo to next message
Mark Miller is currently offline Mark Miller
Messages: 5
Registered: July 2009
Junior Member
I use the following :

Let the bundle throw the exception so that it is unhandled.

in the IApplication start method, after the createDisplay but before createAndRunWorkbench


Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				handleException(t, e);
			}
		});





// This is the error handler

private void handleException(final Thread t, final Throwable e) {
		e.printStackTrace();
		
		final Display display = Display.getDefault();
		if (display.getThread() != t) {
			display.syncExec(new Runnable() {
				@Override
				public void run() {
						
						Status status = new Status(Status.ERROR, "app", e.getLocalizedMessage(), e);
						int openError = ErrorDialog.openError(
								display.getActiveShell(), 
								"Error - Epos will close", 
								"Could not handle the following error", 
								status);
						
						
						if (openError == Window.OK) {
							PlatformUI.getWorkbench().close();
						}

				}
			});
		}
	}

[Updated on: Wed, 30 September 2009 06:56]

Report message to a moderator

Re: How to shutdown on error [message #488907 is a reply to message #488812] Wed, 30 September 2009 12:46 Go to previous message
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
Thanks for the example. But as mentioned in the original post, getWorkbench().close() doesn't work in this case because the workbench may not have been initialized yet (e.g. if the failure occurs in a non-UI bundle that the UI bundle depends on).

Any other solutions?
Previous Topic:Show View and open Perspective in my own RCP
Next Topic:Problem View and Custom Columns
Goto Forum:
  


Current Time: Wed Jul 30 09:19:10 EDT 2014

Powered by FUDForum. Page generated in 0.10397 seconds