RCP Eclipse Global Exception Handling

I want to override global exception handling in an RCP application. Whenever an uncaught exception occurs, I want to register it (using java logging) and then exit the application. I have already overwritten the eventLoopException(Throwable exception) method in the ApplicationWorkbenchAdvisor class. But this only captures event loop exceptions. At the moment, I have also rewritten the postStartup() method as follows:

 public void postStartup() { Policy.setStatusHandler(new StatusHandler() { @Override public void show(IStatus status, String title) { LOGGER.log(Level.SEVERE, "Uncaught Exception", status.getException()); UnexpectedErrorDialog(); PlatformUI.getWorkbench().close(); } }); } 

It logs the exception in my log file and exits the application. But this is clearly not the case, and the exception is displayed twice in the console, because all I do is intercept the display of the exception in the gui dialog for the user. So, how can I correctly overwrite / modify global exception handling so that my code (log) is used instead of my standard code?

+6
source share
2 answers

Thanks to sambi reddy tip, I have now rewritten AbstractStatusHandler in the ApplicationWorkbenchAdvisor class

 @Override public synchronized AbstractStatusHandler getWorkbenchErrorHandler() { if (myStatusHandler == null) { myStatusHandler = new MyStatusHandler(); } return myStatusHandler; } 

MyStatusHandler extends AbstractStatusHandler, and I rewrote the handle method as follows:

 @Override public void handle(StatusAdapter statusAdapter, int style) { if(statusAdapter.getStatus().matches(IStatus.ERROR) && ((style != StatusManager.NONE))) { LOGGER.log(Level.SEVERE, "Uncaught Exception", statusAdapter.getStatus().getException()); UnexpectedErrorDialog(); PlatformUI.getWorkbench().close(); } } 

seems to work correctly, only drawback is that I still get 2 console outputs.

+2
source

I would suggest you use the org.eclipse.ui.statusHandlers extension point

+2
source

All Articles