线程中不可控异常处理

    xiaoxiao2021-03-25  34

    这种捕获方式不经常用到,记录一下吧

    package mytest; import java.lang.Thread.UncaughtExceptionHandler; public class ExceptionHandler implements UncaughtExceptionHandler { @Override public void uncaughtException(Thread t, Throwable e) { System.out.printf("Exception: %s: %s\n", e.getClass().getName(), e.getMessage()); } public static void main(String[] args) { Thread thread = new Thread(new Runnable() { @Override public void run() { int i = 1 / 0; } }, "testExceptionHandler"); thread.setUncaughtExceptionHandler(new ExceptionHandler()); thread.start(); } }
    转载请注明原文地址: https://ju.6miu.com/read-50063.html

    最新回复(0)