Mega Code Archive

 
Categories / Java / Threads
 

Set Uncaught Exception Handler

public class Uncaught implements Runnable {   public static void main(String[] args) {     Thread thread = new Thread(new Uncaught());     thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {       public void uncaughtException(Thread t, Throwable e) {         e.printStackTrace();       }     });     thread.start();   }   public void run() {     throw new ArithmeticException();   } }