如图,问题也在图片中,为什么改成-1,就会抛异常,改成6就不抛了,
下面是完整的代码
public class TryCatchTest {
public static void main(String[] args) {
TryCatchTest tct = new TryCatchTest();
int result = tct.test();
System.out.println("test()方法,执行完毕!返回值为:"+result);
}
public int test(){
int divider = 10;
int result = 100;
try{
while(divider > 6){
divider--;
result = result + 100/divider;
}
return result;
}catch(Exception e){
e.printStackTrace();//打印异常信息的方法
return -1;
}
}
}