本文介绍了我如何能赶上在Java的AWT线程异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想跟踪我们的这些异常的应用程序日志 - 默认的Java只是把它们输出到控制台

We'd like a trace in our application logs of these exceptions - by default Java just outputs them to the console.

推荐答案

有在EDT和EDT外捕获的异常区别开来。

There is a distinction between uncaught exceptions in the EDT and outside the EDT.

Another问题有两个一个解决方案,但如果你想吃掉只是EDT部分...

Another question has a solution for both but if you want just the EDT portion chewed up...

class AWTExceptionHandler {

  public void handle(Throwable t) {
    try {
      // insert your exception handling code here
      // or do nothing to make it go away
    } catch (Throwable t) {
      // don't let the exception get thrown out, will cause infinite looping!
    }
  }

  public static void registerExceptionHandler() {
    System.setProperty('sun.awt.exception.handler', AWTExceptionHandler.class.getName())
  }
}

这篇关于我如何能赶上在Java的AWT线程异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 16:01