0

I am explicitly throwing an exception in action performed method and not catching it , so EDT exception handler should catch it and ideally EDT should stop working but when I click on the button of the frame , EDT is again started . How a thread can be restarted?

2 Answers2

2

When a thread throws an exception that isn't caught, Thread.UncaughtExceptionHandler will be called. If it hasn't been set, the default uncaught exceptionhandler will be called. The handler will display a stacktrace and most likely be restarted, although the documentation doesn't specify what exactly are the steps taken.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • http://stackoverflow.com/questions/4448523/how-can-i-catch-event-dispatch-thread-edt-exceptions discusses the happenings of EDT exceptions. – Kayaman Jul 23 '13 at 12:59
1

The EDT is a special case. It is restarted whenever it is stopped by an uncaught exception being thrown.

This is a good design because it ensures your entire GUI doesn't crash and burn because of an uncaught exception somewhere within, say, a button action.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • Are you claiming that the EDT will actually shut down in case of an exception? – Kayaman Jul 23 '13 at 12:48
  • No, it has an uncaught exception handler that will prevent the thread from dying. – Kayaman Jul 23 '13 at 12:49
  • @Kayaman Do you have a reference that confirms the original thread doesn't stop? An exception handler does not indicate that the same original thread keeps running. See for example http://stackoverflow.com/questions/3020757/java-does-the-edt-restart-or-not-when-an-exception-is-thrown. – Duncan Jones Jul 23 '13 at 12:50
  • True, it will not necessarily be the same thread instance. I'll make edits. – Kayaman Jul 23 '13 at 12:54