这篇教程Java 实例 - 多线程异常处理写得很实用,希望能帮到您。 以下实例演示了多线程异常处理方法: Main.java 文件 class MyThread extends Thread{ public void run(){ System.out.println("Throwing in " +"MyThread"); throw new RuntimeException(); }}class Main { public static void main(String[] args){ MyThread t = new MyThread(); t.start(); try{ Thread.sleep(1000); } catch (Exception x){ System.out.println("Caught it" + x); } System.out.println("Exiting main"); }} 以上代码运行输出结果为: Throwing in MyThreadException in thread "Thread-0" java.lang.RuntimeException at testapp.MyThread.run(Main.java:19)Exiting main Java 实例 - 使用 catch 处理异常 Java 实例 - 获取异常的堆栈信息 |