Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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] by 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
Eclipse UserFriend
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 23 10:55:07 EDT 2025

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

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

Back to the top