How to shutdown on error [message #488508] |
Mon, 28 September 2009 21:28  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.05391 seconds