Eclipse/Java:EDT 上未捕获的异常暂停 EventDispatchThread.run() 中的执行

发布于 2024-12-11 03:25:29 字数 774 浏览 0 评论 0原文

这是我在使用 Eclipse 进行调试时遇到的一个小烦恼。选中“未捕获异常时暂停执行”后,调试器通常会在引发异常的位置暂停线程。然而,事件调度线程上的异常会导致它在 EventDispatchThread.run() 的最后一行暂停。在我恢复线程以允许堆栈跟踪打印到控制台之前,没有关于异常是什么或导致异常的原因的有用信息。

在 Eclipse 中调试以下代码进行演示:

public class SuspendOnUncaughtTest {
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ((Object) null).toString();
            }
        });
    }
}

下面是抛出异常后的样子:

Suspending at EventDispatchThread.run( ) 编辑 10/21/2011: 我猜 Eclipse 或 Java 调试器没有发生任何奇怪的事情,只是在 EventDispatchThread.pumpOneEventForFilters(int) 中捕获并重新抛出异常。我想没有办法告诉 Eclipse“暂停执行将要捕获并可能重新抛出的异常”。太糟糕了。

This is a minor annoyance I have when debugging with Eclipse. With "Suspend execution on uncaught exceptions" checked, the debugger will normally suspend a thread right where the exception was thrown. Exceptions on the Event Dispatch Thread, however, cause it to pause on the last line of EventDispatchThread.run(). There is no useful information about what the exception is or what caused it until I resume the thread to allow the stack trace to print to the console.

Debug the following code in Eclipse to demonstrate:

public class SuspendOnUncaughtTest {
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ((Object) null).toString();
            }
        });
    }
}

And here is what it looks like after the exception is thrown:

Suspended at EventDispatchThread.run()
EDIT 10/21/2011: I guess there's nothing weird going on with Eclipse or the Java debugger, it's just that exceptions are caught and rethrown in EventDispatchThread.pumpOneEventForFilters(int). I suppose there's no way to tell Eclipse to "suspend execution on exceptions that are going to be caught and possibly rethrown". Too bad.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相思故 2024-12-18 03:25:29

在 NeteBeans 中看到类似的结果,但是 Thread.setDefaultUncaughtExceptionHandler() 在此上下文中可能有用。 这里有一个示例

Is see a similar result in NeteBeans, but Thread.setDefaultUncaughtExceptionHandler() may be useful in this context. There's an example here.

笑咖 2024-12-18 03:25:29

据我所知,这个问题没有解决办法。 Eclipse 的行为是正确的,正确的行为只是令人烦恼。

As far as I can tell, there is no solution to this. Eclipse is behaving correctly, the correct behavior is just annoying.

指尖凝香 2024-12-18 03:25:29

我遇到了这个问题并找到了对我有用的东西。

我正在使用 Kepler,并且能够通过转到调试器透视图的断点选项卡并取消选择 EventDispatchThread 上的复选框来停止此操作。

在此处输入图像描述

I had this issue and found something that worked for me.

I am using Kepler, and was able to stop this by going to the breakpoints tab of the debugger perspective and deselecting the checkbox on the EventDispatchThread.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文