public class Computer {
double c ;
public void div(double a,double b){
try{
c = a/b;
}
catch(NumberFormatException e){
e.printStackTrace();
System.out.println("格式化数据异常。");
}
catch(ArithmeticException e){
e.printStackTrace();
System.out.println("出现算术异常。");
}
catch(Exception e){
e.printStackTrace();
System.out.println("出现其他异常。");
}
System.out.println("两个数的商是:"+c);
}
}
public class test {
public static void main(String[] args) {
Computer c = new Computer();
c.div(0,0);
}
}
运行结果
两个数的商是:NaN
为什么没有抓住异常呢?