public class UncaughtExceptionTest2 { public UncaughtExceptionTest2() { Thread.setDefaultUncaughtExceptionHandler(new UEHandler1()); Thread thread1 = new Thread(new Task(), "task1"); thread1.start(); Thread thread2 = new Thread(new Task(), "task2"); thread2.setUncaughtExceptionHandler(new UEHandler2()); thread2.start(); } class UEHandler1 implements Thread.UncaughtExceptionHandler { public void uncaughtException(Thread t, Throwable e) { System.out.print("UEHandler1 catches the Uncaught Exception!!!"); System.out.println(" Thread: " + t); e.printStackTrace(); } } class UEHandler2 implements Thread.UncaughtExceptionHandler { public void uncaughtException(Thread t, Throwable e) { System.out.println("UEHandler2 catches the Uncaught Exception!!!"); System.out.println(" Thread: " + t); e.printStackTrace(); } } class Task implements Runnable { private void foo() { } public void run() { try { Thread.sleep(1000L); } catch (InterruptedException ex) {} throw new RuntimeException(); } } public static void main(String[] args) { new UncaughtExceptionTest2(); } }