In order to report all uncaught exceptions of all background
threads, you must place all the threads in your own
ThreadGroup
. For this
ThreadGroup
you redefine the
method:
void uncaughtException(Thread t, Throwable e)
In this method you can report the exception chain in the format, and to the destination, you want. You should try to report to the user interface (UI), if the thread was created or started by an UI event, e.g. if it implements an action, which would last too long for the user to await its completion.
Since Java 5 there is also such a possibility without the necessity to create thread groups. The method
public static void setDefaultUncaughtExceptionHandler( Thread.UncaughtExceptionHandler eh )
installs a last-resort exception handler for all thread groups together.