try-catch-finally用法
程序员文章站
2022-04-06 15:54:07
...
public class Main {
public static void main(String[] args) {
try {
int a = 10;
int b;
for (int i = 2;i >= -1;i--){
b = a / i;
System.out.println("i="+i);
}
}catch (ArithmeticException e){
System.out.println("除数为0!!!");
}catch (Exception e){
System.out.println("未知错误");
}finally {
System.out.println("退出安全判断");
}
}
}