位置:首頁 > 軟件操作教程 > 編程開發(fā) > Java > 問題詳情

Java try catch示例,多條catch捕獲異常

提問人:劉旭39發(fā)布時間:2020-11-30

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());

}

}

}(YSDXQ@R056YOXE1`B2%I[G.png


繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(fù)(0)
返回頂部