How do I configure a default handler for exceptions that happen in my threads?

John Zukowski

The setUncaughtExceptionHandler() method of Thread, introduced in JDK 5.0, allows you to configure this behavior by letting you attach an implementation of Thread.UncaughtExceptionHandler. The interface offers a single method:

public interface Thread.UncaughtExceptionHandler {
    public void uncaughtException(Thread, Throwable);
By attaching a handler to your thread, if an uncaught exception happens (aka runtime exception), the registered handler will respond.
public class MyHandlerTest {
  public static void main(String args[]) throws Exception {
    Thread.UncaughtExceptionHandler handler = new SomeHandler();
    System.out.println(1 / 0);