イベント ディスパッチ スレッドでスローされた例外をキャッチするコードを次に示します。
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");
}
}
イベント ディスパッチ スレッドでスローされた例外が UncaughtExceptionHandler によって処理されないという警告を見てきましたが、私の例ではそうではないようです。登録行がコメントアウトされていても、そのまま残されていても、同じように機能しsun.awt.exception.handler
ます。