Я использую класс под названием MyExceptionHandler
, который реализует Thread.UncaughtExceptionHandler
для обработки нормальных исключений в моем проекте.
Как я понимаю, этот класс не может поймать исключения EDT, поэтому я попытался использовать это в методе main()
для обработки исключений EDT:
public static void main( final String[] args ) {
Thread.setDefaultUncaughtExceptionHandler( new MyExceptionHandler() ); // Handle normal exceptions
System.setProperty( "sun.awt.exception.handler",MyExceptionHandler.class.getName()); // Handle EDT exceptions
SwingUtilities.invokeLater(new Runnable() { // Execute some code in the EDT.
public void run() {
JFrame myFrame = new JFrame();
myFrame.setVisible( true );
}
});
}
Но до сих пор он не работает. Например, при инициализации JFrame я загружаю его метки из файла пакета в конструкторе следующим образом:
setTitle( bundle.getString( "MyJFrame.title" ) );
Я удалил ключ MyJFrame.title
из файла пакета для проверки обработчика исключений, но он не сработает! Исключение обычно печаталось в журнале.
Я делаю что-то не так здесь?