UncaughtExceptionHandler的没抓一些例外 [英] UncaughtExceptionHandler not catching some exceptions

查看:148
本文介绍了UncaughtExceptionHandler的没抓一些例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个的UncaughtExceptionHandler如图这文章

I have created an UncaughtExceptionHandler as shown in this article.

我也注册了这个处理程序来捕获所有线程中的异常是这样的:

I have also registered this handler to catch exceptions in all threads like this:

    Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());

然而,它缺少一些例外情况:

However, it is missing some exceptions:

Exception occurred during event dispatching:
java.lang.RuntimeException: Critical error!
    at com.acme.MyClass.myMethod(MyClass.java:46)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:602)
    at java.awt.EventQueue$1.run(EventQueue.java:600)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
    at java.awt.Dialog$1.run(Dialog.java:1046)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:602)
    at java.awt.EventQueue$1.run(EventQueue.java:600)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:616)
    at java.awt.EventQueue$2.run(EventQueue.java:614)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

为什么缺少的例外是这样?

Why is it missing exceptions like this?

推荐答案

大概线程此异常被抛出已经拥有了自己未捕获的异常处理程序。在这种情况下不使用的默认处理。你可以通过调用相关的线程上的 getUncaughtExceptionHandler()方法(它是事件调度线程这里)检查。

Probably the thread in which this exception is thrown already has its own uncaught exception handler. In this case the default handler is not used. You can check this by calling the getUncaughtExceptionHandler() method on the relevant thread (which is the event dispatcher thread here).

这也可能是这个线程属于一个特殊的线程组,其中处理异常而不是将其委托给默认的处理程序。

It could also be that this thread belongs to a special ThreadGroup, which handles the exception instead of delegating it to the default handler.

在这两种情况下,你可以明确地设置你的处理程序,这个线程与 setUncaughtExceptionHandler()方法的处理程序。

In both cases, you could explicitly set your handler as the handler of this thread with the setUncaughtExceptionHandler() method.

这篇关于UncaughtExceptionHandler的没抓一些例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆