Intercepting Eclipse e4 platform exceptions

爱⌒轻易说出口 提交于 2019-12-12 04:48:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!