使用多个catch语句捕获多个异常
import java.io.FileInputStream; import java.io.IOException; public class Main {//from n o w j a v a . c o m public static void main(String[] args) { try { Class<?> stringClass = Class.forName("java.lang.String"); FileInputStream in = new FileInputStream("myFile.log"); // Can throw IOException in.read(); } catch (IOException e) { System.out.println("There was an IOException " + e); }