自定义除数不能为负数的异常

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;
}
}

posted on 2017-03-27 21:37  陈涛Java138  阅读(411)  评论(0)    收藏  举报