相关疑难解决方法(0)

为什么要设置"sun.awt.exception.handler"属性呢?

这里有一些代码可以捕获Event Dispatch Thread上抛出的异常:

package com.ndh.swingjunk;

import java.awt.EventQueue;

import javax.swing.JFrame;

public class EntryPoint {

    public static void main(String[] args) {
        Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());
//      System.setProperty("sun.awt.exception.handler", MyExceptionHandler.class.getName());

        EventQueue.invokeLater(new Runnable() 
        {
            public void run() 
            {
                new SomeWindow("foo").setVisible(true);
            }
        });
    }
}

class SomeWindow extends JFrame {
    public SomeWindow(String title) {
        this.setTitle(title);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        throw new RuntimeException("hello");
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经看到警告,事件调度线程抛出的异常不会被UncaughtExceptionHandler处理,但对我的例子来说似乎并非如此; 无论注册行是注释掉还是遗留下来,它的工作方式都是一样的.我的示例是以某种方式搞砸了,还是注册了sun.awt.exception.handler不再需要的异常处理程序?

java swing awt uncaught-exception

8
推荐指数
1
解决办法
2738
查看次数

javafx,获取对应用程序线程的引用

在摇摆我们有:

boolean SwingUtilities.isEventDispatchThread()
Run Code Online (Sandbox Code Playgroud)

如果从 Swing 事件调度线程调用,则返回 true。

javafx 中有类似的东西吗?

javafx-2

2
推荐指数
1
解决办法
1160
查看次数

标签 统计

awt ×1

java ×1

javafx-2 ×1

swing ×1

uncaught-exception ×1