In order to report all uncaught exceptions in a Swing
application, which occur during the execution of an UI-event-triggered
action, it is sufficient to install one central exception handler
using the undocumented system property
sun.awt.exception.handler
, see more in Debug Tips for AWT.
This undocumented behaviour is wrapped by a MulTEx service. You
can implement the interface
multex.AwtExceptionHandler
, and install
this class by the method
multex.Awt.setAwtExceptionHandlerClass
. Then
any exception propagating up to the AWT/Swing event-dispatch thread
will be reported by the handler's method
handle(Throwable)
. In this method you should
call a multex.Swing.report
method.
In order to block input to the GUI application while reporting
an exception, it is necessary to locate the application's frame and
use it in the central exception handler's call to report(...) as the
ownerHook
.
If an application has several frames, and it is not possible to
determine automatically, which UI component must be blocked during
exception reporting, then you should use an own
UiAction
base class as was described
earlier.
Attention: Propagating an exception from the method
actionPerformed
will leave Swing in a dirty
state. Sometimes the focus of a menu item will be highlighted in
another place, than where Swing assumes it to be. So you should on the
one hand install such a last-resort exception reporting, but
nevertheless you need an UiAction
for reporting
exceptions in all user-triggered actions.