未抛出异常,帮忙看下哪里出问题了吧class DevideByMinusException extends Exception{
int devisor;
public DevideByMinusException(String msg,int devisor){

super(msg);

this.devisor=devisor;
}public int getDevisor(){
return devisor;

}
}
class Test{
Test(){}
public int devide(int x,int y) throws ArithmeticException,DevideByMinusException{
System.out.println("1");
if (y<0){
System.out.println(y);
throw new DevideByMinusException("被除数为负数",y);
}
System.out.println("5");
int result=x/y;
System.out.println("3");
return x/y;
}
}public class TestExeption{
public static void main(String[] args) {
try{

//int result=new Test().devide(3,0);
//int result=new Test().devide(3,-1);
Test t=new Test();
int r=t.devide(3,-1);
//int result=new Test().devide(3,1);
System.out.println("The result is"+r);
}catch (DevideByMinusException e){
e.getMessage();
e.getDevisor();
}catch(ArithmeticException e){
e.getMessage();
}catch(Exception e){
e.getMessage();
}
}
}

解决方案 »

  1.   

    class DevideByMinusException extends Exception{
    int devisor;
    public DevideByMinusException(String msg,int devisor){

    super(msg);

    this.devisor=devisor;
    }public int getDevisor(){
    return devisor;

    }
    }class Test{ Test(){} public int devide(int x,int y) throws      ArithmeticException,DevideByMinusException{
    System.out.println("1");
        //throw new DevideByMinusException("被除数为负数",y);
     //throw new NullPointerException();
    if (y<0)
                  {
    System.out.println("ere"  + y);
    throw new DevideByMinusException("被除数为负数",y);
    }
    System.out.println("5");
    int result=x/y;
    System.out.println("3");
    return x/y;
    }
    } class TestExeption{
    public static void main(String[] args) {
    try{

    //int result=new Test().devide(3,0);
    //int result=new Test().devide(3,-1);
    Test t=new Test();
    int r=t.devide(3,-1);
    //int result=new Test().devide(3,1);
    System.out.println("The result is"+r);
    }catch (DevideByMinusException e){
    System.out.println(e.getMessage());
    e.getDevisor();
    }catch(ArithmeticException e){
    e.getMessage();
    }catch(Exception e){
    e.getMessage();
    }
    }
    }你的异常已经被抛出了,只是你没有打印出来,在catch 中要用System.out.println();