public class Demo {
static public void action() throws ClassNotFoundException {
int a = 1;
if (a > 0) {
throw new ClassNotFoundException();// 拋出類無法找到例外 } }
public static void main(String[] args) {
try {
action(); }
catch (NullPointerException e) {// 捕捉空指標例外 e.printStackTrace();
}
}
}
uj5u.com熱心網友回復:
編譯錯誤,checked exception 必須捕獲或再次拋出uj5u.com熱心網友回復:
拋出的例外是ClassNotFoundException,為什么try catch是NullPointerException,捕捉的時候應該也是ClassNotFoundException才對轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/108868.html
標籤:Java相關
