我把数据类型改为float型,为什么运行加果不能抛出“错误”,而是“结果:infinity”。
package com.test;
public class ThrowException {
public static void main(String[] args) {
ThrowException t=new ThrowException();
float result=t.divide();
System.out.println("结果:"+result);
}
public float divide(){
float result=100;
float divider=10;
try {
while(divider>0){
divider--;
result+=100/divider;
}
return result;
} catch (Exception e) {
System.out.println("错误");
return -1;
}
}
}