import java.util.concurrent.TimeUnit;
public class ThreadException {
public static void main(String[] args) {
Thread t = new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(3);
int res = 1/0;
} catch (InterruptedException e) {
e.printStackTrace();
}
}, "error");
t.setUncaughtExceptionHandler((thread, e)->{
System.out.println(e);
System.out.println(thread);
});
t.start();
}
}
输出结果: