| 这篇教程Java 实例 - 异常处理方法写得很实用,希望能帮到您。 
 以下实例演示了使用 System 类的 System.err.println() 来展示异常的处理方法:  ExceptionDemo.java 文件class ExceptionDemo{    public static void main(String[] args) {        try {            throw new Exception("My Exception");        } catch (Exception e) {            System.err.println("Caught Exception");            System.err.println("getMessage():" + e.getMessage());            System.err.println("getLocalizedMessage():" + e.getLocalizedMessage());            System.err.println("toString():" + e);            System.err.println("printStackTrace():");            e.printStackTrace();        }    }} 以上代码运行输出结果为: Caught ExceptiongetMessage():My ExceptiongetLocalizedMessage():My ExceptiontoString():java.lang.Exception: My ExceptionprintStackTrace():java.lang.Exception: My Exception   at ExceptionDemo.main(ExceptionDemo.java:5) Java 实例 - 遍历目录
 Java 实例 - 多个异常处理(多个catch)
 |