Java tutorial
import java.lang.Thread.UncaughtExceptionHandler; public class Main { public static void main(String[] args) { Thread thread = new Thread() { public void run() { throw new NullPointerException(); } }; thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread arg0, Throwable arg1) { arg1.printStackTrace(); } }); thread.start(); } }