Java try catch示例,多条catch捕获异常
import java.io.IOException;
//try catch示例,多条catch捕获异常
public class Demo {
public static void main(String[] args) throws Exception {
try {
Class.forName("className");
} catch (IllegalArgumentException e) {
System.out.println("捕获异常:" + e.getClass().getName());
System.out.println("异常内容为:" + e.getMessage());
} catch (IOException e) {
System.out.println("捕获异常:" + e.getClass().getName());
System.out.println("异常内容为:" + e.getMessage());
} catch (Exception e) {
System.out.println("捕获异常:" + e.getClass().getName());
System.out.println("异常内容为:"+ e.getMessage());
}
}
}
点击加载更多评论>>