public class TestException1 {
public static void main(String[] args) {
System.out.println(except());
}
public static int except() {
int s = 0;
try {
System.out.println(2 / 0);
} catch (ArithmeticException e1) {
e1.printStackTrace();
System.out.println("除数为零,程序自动退出");
return s;
}
finally {
s = 1;
System.out.println("这里可以执行,说明s在finally中被赋值为1也无用,说明finally语句块中不能通过给变量赋新值来 改变return的返回值,也建议不要在finally块中使用return语句,没有意义还容易导致错误");
}
return -1;
}
}