Online Java Compiler By
JavaTpoint.com
public class JavaSetDefaultExceptioneExp implements Runnable { public void run() { throw new RuntimeException(); } public static void main(String[] args) { Thread thread = new Thread(new JavaSetDefaultExceptioneExp()); thread.setDefaultUncaughtExceptionHandler(new Thread. UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable e) { System.out.println("Exception caught: " + e); } }); // call run() function thread.start(); } }
Output