throws 使用在函數上, 後面跟的是異常類.可以跟多個,用逗號隔開
throw使用在函數內, 後跟的是異常對象
class Demo {
public int div(int a, int b) throws NegativeException {
if (b < 0) {
throw new NegativeException("除數是負數了");
}
return a / b;
}
}