A线程调用B线程,B线程发生异常,A怎么知道B线程发生异常了
public class Demo { public static void main(String[] args) throws Exception, SecurityException { Thread t = new Thread(() -> { // int i = 1 / 0; //这里只能抛出运行时异常,如果是检查异常,会提示try-catch throw new RuntimeException("发生异常了"); }); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { System.out.println(t.getName()); System.out.println(e.getMessage()); } }); t.start(); } }