使用Thread的Java示例异常 Java示例打印异常堆栈 Java示例用户定义的异常 使用Thread的Java示例异常 class MyThread extends Thread{ public void run(){ System.out.println("Throwing in " +"MyThread"); throw new RuntimeException(); } } public 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"); } } Java示例打印异常堆栈 Java示例用户定义的异常