问题
Using Eclipse RCP 3.x, it is possible to create a custom AbstractStatusHandler to intercept platform exceptions. One way to do this, is to override the getWorkbenchErrorHandler() method in the ApplicationWorkbenchAdvisor class like this:
@Override
public synchronized AbstractStatusHandler getWorkbenchErrorHandler()
{
if (m_errorHandler == null)
{
m_errorHandler = new MyWorkbenchErrorHandler(this);
}
return m_errorHandler;
}
After doing a lot of research in Eclipse forums, stackoverflow and in the Lars Vogel Eclipse 4 book, I have not been able to find an equivalent way to do this using e4.
Any help would be appreciated.
回答1:
You can put our own IEventLoopAdvisor
into the context. A good place to do this is on @PostContructCreate
in your life cycle handler.
context.set(IEventLoopAdvisor.class, new IEventLoopAdvisor() {
@Override
public void eventLoopException(Throwable exception) {
... handle exception here ...
}
...
});
If there is no IEventLoopAdvisor
in the context the platform will use a default. You can see how the platform does this in PartRenderingEngine
(at the time of writing on line 1102):
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
来源:https://stackoverflow.com/questions/29900137/intercepting-eclipse-e4-platform-exceptions