CatchWho.Javaspa
源代碼:blog
public class CatchWho { it
public static void main(String[] args) { io
try { class
try { 程序
throw new ArrayIndexOutOfBoundsException(); //要處理的問題im
} static
catch(ArrayIndexOutOfBoundsException e) { img
System.out.println("ArrayIndexOutOfBoundsException"+ "/內層try-catch"); 截圖
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("發生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) { System.out.println("ArrayIndexOutOfBoundsException" + "/外層try-catch");
}
}
}
預測程序運行結果:ArrayIndexOutOfBoundsException/外層try-catch
發生ArithmeticException
ArrayIndexOutOfBoundsException/外層try-catch
實際運行結果截圖:
源代碼:
public class CatchWho2 {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArithmeticException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/內層try-catch");
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("發生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外層try-catch");
}
}
}
預測程序運行結果:ArrayIndexOutOfBoundsException/內層try-catch
發生ArithmeticException
ArrayIndexOutOfBoundsException/外層try-catch
實際運行結果截圖: