public class TestThreadException {
public static void main(String[] args) {
System.out.println("begin main");
Thread thread = new Thread(() -> {
int i = 1 / 0;
}, "myThread");
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println(String.format("%s发生异常%s", t.getName(), e.getMessage()));
}
});
thread.start();
System.out.println("end main");
}
}
Java捕获线程异常
猜你喜欢
转载自blog.csdn.net/shuyizhi/article/details/79716060
今日推荐
周排行