自定义除数不能为负数的异常
public class ChuShunegativeException extends Exception {
public static void main(String[] args) {
try {
FuShu(4,-5);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ChuShunegativeException(String s) {
super(s);
}
public static int FuShu(int a,int b)throws Exception{
if(b<0){
throw new ChuShunegativeException(b+"是负数不能作为除数");
}
return a/b;
}
}
浙公网安备 33010602011771号