package demo;
class TestA{
public int devide(int x,int y) throws ArithmeticException , DevideByMinusException{
if(y<0)
throw new DevideByMinusException("被除数为负",y);
int result=x/y;
return result;
}
}
public class TestException {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
try{
// int result=new TestA().devide(3,0);
int result=new TestA().devide(3,-1);
System.out.println(result);
}catch(ArithmeticException e){
System.out.println("in >>ArithmeticException<< ");
System.out.println(e.getMessage());
// e.printStackTrace();
}catch(DevideByMinusException e){
System.out.println("in >>DevideByMinusException<< ");
System.out.println(e.getMessage());
// e.printStackTrace();
}
System.out.println("program is running here,that is normal!");
}
}
class DevideByMinusException extends Exception{
int devisor;
public DevideByMinusException(String msg,int devisor){
super(msg);
this.devisor=devisor;
}
public int getDevisor(){
return devisor;
}
}