public class FunctionException {
public static void main(String[] args) {
FunctionException tt=new FunctionException();
tt.function();
int divisor=tt.function();
int Divisor=tt.function();
System.out.println("接收返还值Divisor"+Divisor);
System.out.println("接收返还值divisor"+divisor);
}
public int function() {
try {
int Divisor=100;
int divisor=3;
int JS;
do {
JS=Divisor/divisor;
divisor--;
} while (divisor>-1);
return Divisor;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("出现了一个错误");
}
return -1;
}
}
result result在循环外,只有while循环完才会返回result, 但此循环必定触发异常,循环到divisor=0时,跳到catch,执行return -1;是不会执行return result的
正有此疑问,谢谢