?? 7.13rethrowexception.java
字號:
public class RethrowException{
private static int a=10,b=0;
public static void main(String args[]){
try{
divideOperation();
}
catch(ArithmeticException exception){ //捕獲被零除的異常
System.out.println("ArithmeticException is handled in mainmethod!");
System.err.println(exception.toString());
}
}
public static void divideOperation () throws ArithmeticException{ //聲明被零除的異常
try {
if (b == 0){
System.err.println(" --- Calling method divideoperation---");
throw new ArithmeticException ("Divided by zero!"); //拋出被零除的異常
}
System.out.println ("a / b =" + a / b);
}
catch (ArithmeticException exception){ //捕獲被零除的異常
System.err.println("ArithmeticException is caught in divideOperation method!");
System.err.println("ArithmeticException is thrown in divideOperation method!");
throw exception;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -