我们希望在我们的应用程序日志中跟踪这些异常-默认情况下,Java只将它们输出到控制台。
发布于 2008-09-18 21:27:41
EDT中的未捕获异常和EDT外部的未捕获异常之间存在差异。
Another question has a solution for both,但是如果你只想要美国东部夏令时的那部分...
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())
}
}
发布于 2015-01-09 18:57:04
从Java7开始,你必须以不同的方式来做,因为sun.awt.exception.handler
黑客不再工作了。
Here is the solution (来自Uncaught AWT Exceptions in Java 7)。
// Regular Exception
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());
// EDT Exception
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
// We are in the event dispatching thread
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler());
}
});
https://stackoverflow.com/questions/95767
复制相似问题