简体   繁体   English

Eclipse E4 RCP全局错误处理

[英]Eclipse E4 RCP global error handling

My problem is the same as the one in this thread : "I want to set a custom error handler, which is called each time an unexpected error occurs. How can I achieve that?" 我的问题与该线程中的问题相同:“我想设置一个自定义错误处理程序,每次发生意外错误时都会调用该处理程序。如何实现呢?”

How can I do this in E4? 我如何在E4中做到这一点? In E3 it can be achieved by overriding the eventLoopException method of the ApplicationWorkbenchAdvisor 在E3中,可以通过重写ApplicationWorkbenchAdvisoreventLoopException方法来实现

The thread links to another thread where a StatusReporter is being extended. 该线程链接到另一个正在扩展StatusReporter 线程 Now I am able to extend StatusReporter but its methods are not invoked automatically when some unexpected exception occurs. 现在,我可以扩展StatusReporter但是当发生某些意外的异常时,不会自动调用其方法。 Also I get a discouraged access warning that StatusReporter is not an API. 另外,我还会收到不鼓励访问的警告,提示StatusReporter不是API。

Another approach , as mentioned in the wiki, is to use StatusHandler . 如Wiki中所述, 另一种方法是使用StatusHandler But I do not want to invoke the StatusHandler manually. 但是我不想手动调用StatusHandler I want a global handler which automatically picks up un-handled exceptions... 我想要一个全局处理程序,该处理程序自动拾取未处理的异常...

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks, Jehan 谢谢约翰

You can put your own implementation of IEventLoopAdvisor in to the context. 您可以将自己的IEventLoopAdvisor实现IEventLoopAdvisor上下文中。 The @PostContextCreate method of your LifeCycle class is a good place to add this. LifeCycle类的@PostContextCreate方法是添加此方法的好地方。

IEventLoopAdvisor has two methods: IEventLoopAdvisor有两种方法:

@Override
public void eventLoopIdle(final Display display)
{
  // Called whenever the RCP is idle, you can do other things here
  // but it is very important to call 'display.sleep()'

  display.sleep();
}

@Override
public void eventLoopException(final Throwable exception)
{
  // Add code for unhandled exceptions
}

Note: IEventLoopHandler is an internal class so normally it should be avoided but this usage seems to be sanctioned. 注意: IEventLoopHandler是一个内部类,因此通常应避免使用该类,但此用法似乎受到认可。

If you want to override the logging of all messages you can create your own class derived from org.eclipse.e4.core.services.log.Logger and inject that in to the Eclipse context. 如果要覆盖所有消息的日志记录,则可以创建自己的派生自org.eclipse.e4.core.services.log.Logger的类,并将其注入Eclipse上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM