错题解析
public class Demo{
public static void main(String[] args){
System.out.print(getNumber(0));
System.out.print(getNumber(1));
System.out.print(getNumber(2));
System.out.print(getNumber(4));
}
public static int getNumber(int num){
try{
int result = 2 / num;
return result;
}catch (Exception exception){
return 0;
}finally{
if(num == 0){
return -1;
}
if(num == 1){
return 1;
}
}
}
}
输出结果 -1110
finally一定会在return 前执行,如果finally 中含有return 会导致catch中的return 失效