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("異常內(nèi)容為:" + e.getMessage());
} catch (IOException e) {
System.out.println("捕獲異常:" + e.getClass().getName());
System.out.println("異常內(nèi)容為:" + e.getMessage());
} catch (Exception e) {
System.out.println("捕獲異常:" + e.getClass().getName());
System.out.println("異常內(nèi)容為:"+ e.getMessage());
}
}
}
點(diǎn)擊加載更多評(píng)論>>