views:

285

answers:

3

Hello,

At first I thought this would be question often asked, however trying (and failing) to look up info on this proved me wrong.

Is there a mechanism in Eclipse platform for centralized exception handling of exceptions?

For example... You have plug-in project which connects to a DB and issues queries, results of which are used to populate some e.g. views. This is like the most common example ever. :) Queries are executed almost for any user action, from every UI control the plug-in provides. Most likely the DB Query API will have some specific to the DB SomeDBGeneralException declared as being thrown by it. That's OK, you can handle those according to whatever your software design is. But how about unchecked exceptions which are likely to occur, e.g. , when communication with DB suddenly breaks for some network related reason? What if in such case one would like to catch those exceptions in a central place and for example provide user friendly message to the user (rather than the low level communication protocol api messages) and even some possible actions the user could execute in order to deal with the specific problem?

Thinking in Eclipse platform context, the question may be rephrased as "Is there an extension point like "org.eclipse.ExceptionHandler" which allows to declare exception handlers for specific (some kind of filtering support) exceptions giving a lot of flexibility with the actual handling?"

+1  A: 

You may override the public void eventLoopException(Throwable exception) from WorkbenchAdvisor

Quoted from its javadoc:

This method is called when the code handling a UI event throws an exception. In a perfectly functioning application, this method would never be called. In practice, it comes into play when there are bugs in the code that trigger unchecked runtime exceptions.

pimpf0r
Great! Although I was hoping that there is something more out-of-the-box high level API. Thanks I will give it a shot!
Svilen
A: 

But what about if i want to handle unchecked exceptions for single plugin only in some centralized way.The workbench is already set and active.I assume overriding WorkBencAdvisor will not help as it is not possible to switch current advisor with my overriden one. Is there any other approach that can handle my case.

Atanas
A: 

Yes, Eclipse does provide a framework as you describe.

See http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/ua_statushandling_defining.htm for details of the extension point.

A 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 to look at InternalErrorDialog in the org.eclipse.ui plug-in. This displays the stack trace, which you probably don't want, but it extends ErrorDialog and provides an example that you can copy.