Search code examples
eclipse-rcprcpe4

Replace default pop-up window when exception throws on top level in RCP 4 application


How can I replace default pop-up window when exception throws on top level in RCP 4 application?

Default error pop-up window


Solution

  • You can set a class implementing IEventLoopAdvisor in the application Eclipse Context. This is given all unhandled errors.

    Something like:

    class EventLoopAdvisor implements IEventLoopAdvisor
    {
      @Override
      public void eventLoopIdle(final Display display)
      {
        display.sleep();
      }
    
    
      @Override
      public void eventLoopException(final Throwable exception)
      {
        // TODO Your code
      }
    }
    

    Note: It is extremely important to call display.sleep in the eventLoopIdle method.

    A good place to set this up is the @PostContextCreate of your LifeCycle class (if you have one):

    @PostContextCreate
    public void postContextCreate(final IEclipseContext context)
    {
      context.set(IEventLoopAdvisor.class, new EventLoopAdvisor());
    }
    

    Note: IEventLoopAdvisor is an internal class so normally I would not advise using it, but this use does seem to be allowed.