package com.zhengHong.chongZaiClass;
public class Calcul {
//throws 声明当前方法可能抛出异常,如果有异常就直接抛出去,没有了了
//如果声明抛出的异常是RuntimeException的类以及下层类的异常可处理也可不处理
//如果声明的异常不是RuntimeException上层类时,必须处理,如果不处理会出现编译错误
//在main函数中处理
//两种异常处理方式
//1、处理,作为
//2、main函数也抛出异常,抛给JVM都不作为,直接报错
public int division(int i,int j) throws ArithmeticException{
int result = 0;
try{
result = i/j;
}catch (ArithmeticException e){
throw e;//只抛不作为,实际抛出异常
}
return result;
}
//异常的抛出声明抛出的异常必须大于实际抛出的异常
//重写中异常的抛出,子类中小于等于父类异常
// public int division(int i,int j) throws ArithmeticException {
// result = i / j;
// }
}