class FuShuException extends Exception{
public FuShuException(){
}
public FuShuException(String mes){
super(mes);
}
public double func(int a,int b) throws FuShuException{
if(b<0)
throw new FuShuException("除数为负数了");
return a/b;
}
}
public class YiChang {
public static void main(String[] args) {
FuShuException ax=new FuShuException();
try{
double result=ax.func(2, -3);//把异常抛给catch
System.out.println(result);
}catch(FuShuException e1){//抓住该异常并进行处理
System.out.println(e1.toString());
}catch(ArithmeticException e2){
System.out.println(e2.toString());
}
System.out.println("over");
}
} |
|