1:Exception 异常 放在自定义的异常前面 就报错,为啥? 2:为什么传入的参数为(3 ,'a'),没有报错,结果为0,为啥? class throw_exp extends Exception{ int dev; public throw_exp(String msg, int dev){ super(msg); this.dev = dev; } public int GetDev(){ return dev; } } public class Test_throw { public static void main(String[] args) { try { int result = new Test_throw().devide(3,'b'); //int result = new Test_throw().devide(3, 0); //int result = new Test_throw().devide(3, -1); System.out.println("结果为:"+ result); } catch(throw_exp e){ System.out.println("throw_exp" + e.getMessage() + e.GetDev()); }//自定义异常 catch(ArithmeticException e){ System.out.println("ArithmeticException" + e.getMessage()); }//在算术运算中发生的异常,如除以0 catch(Exception e){ System.out.println("Exception" + e.getMessage()); } } public int devide(int x,int y) throws ArithmeticException, throw_exp{ if(y < 0) throw new throw_exp("被除数为负数",y); int result = x/y; return result; } }