finally{}代码块
package Exception;
/*
* finally{}代码块
*
* finally{]代码块是必须要被执行的,不管异常是否处理成功,该代码块里面的代码体都会被执行,
*/
public class FinallyException {
public static void main(String[] args) {
try{
div(4, 0);
}catch(ArithmeticException ae){
System.out.println("出现了算术异常!!!");
}finally{ //finally代码块是必须处理的
System.out.println("异常处理完毕了!!!");
}
}
public static int div(int a, int b)throws ArithmeticException{
return a / b;
}
}
浙公网安备 33010602011771号