Centralized exception handling for the Eclipse plugin

At first I thought that questions would be often asked, but the attempt (and inability) to find information about this turned out to be wrong to me.

Is there a mechanism in the Eclipse platform for centrally handling exception exceptions?

For example ... You have a plug-in project that connects to the database and issues queries, the results of which are used to populate some, for example. Views This seems like the most common example. :) Requests are executed for almost any user action, from every user interface that the plugin provides. Most likely, the DB Query API will have some DB-specific SomeDBGeneralException declared as thrown by it. This is normal, you can handle them according to your software. But what about uncontrolled exceptions that can occur, for example, when a connection to a database suddenly breaks down for some reason related to the network? What if in this case you would like to catch these exceptions in a central place and, for example, provide the user with a user-friendly message (and not messages about the low-level protocol api) and even some possible actions that the user could perform, to deal with a specific problem?

Reflecting on the context of the Eclipse platform, the question might be rephrased as "Is there an extension point like" org.eclipse.ExceptionHandler "that allows you to declare exception handlers for certain (some filtering support) exceptions that give more flexibility with the actual handling?"

+6
eclipse exception-handling
source share
2 answers

You can override public void eventLoopException(Throwable exception) from WorkbenchAdvisor

Quoted from his javadoc:

This method is called when the user interface event processing code throws an exception. In a perfectly functioning application, this method will never be called. In practice, it goes into play if there are errors in the code that trigger an uncontrolled runtime of the exception .

+5
source share

Yes, Eclipse provides the framework you are describing.

For more information about the extension point, see http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/ua_statushandling_defining.htm .

The starting point is to look at the default implementation: WorkbenchErrorHandler. You will need to implement your own class that extends AbstractStatusHandler. You might also like looking at InternalErrorDialog in the org.eclipse.ui plugin. This displays a stack trace that you probably don't want, but it extends ErrorDialog and provides an example that you can copy.

+3
source share

All Articles