本帖最后由 张然龙 于 2014-5-2 19:08 编辑  
 
在这种情况是可以 捕获两个的! 为了满足楼主的需要我只能这么做了!在开发中没有人这么干! 
代码如下↓ 
 
 
- class Demo3   
 
 - {
 
 -         public static void main(String args[])
 
 -         {
 
 -                 ShuXue s = new ShuXue();
 
 -                 try
 
 -                 {
 
 -                         int x = s.div(-8,-4);
 
 -                         System.out.println(x);
 
 -                 }
 
 -                 catch (FuShuException e)
 
 -                 {
 
 -                         System.out.println("已经解决被除数为负数的异常了!!");
 
 -                         try
 
 -                         {
 
 -                                 int x = s.div(-8,-4);
 
 -                                 System.out.println(x);
 
 -                         }
 
 -                         catch (FuShuTwoException l)
 
 -                         {
 
 -                                 System.out.println("已经解决除数为负数的异常了!!");
 
 -                         }
 
 -                         catch (FuShuException l)
 
 -                         {
 
 -                                 System.out.println("已经解决被除数为负数的异常了!!");
 
 -                         }
 
 -                 }
 
 -                 catch (FuShuTwoException e)
 
 -                 {
 
 -                         System.out.println("已经解决除数为负数的异常了! -_-");
 
 -                 }
 
 -                 System.out.println("over");
 
 -         }
 
 - }
 
 - class ShuXue 
 
 - {
 
 -         public int div(int num1,int num2) throws  FuShuException,FuShuTwoException
 
 -         {
 
 -                 if(num1<0)
 
 -                         throw new FuShuException();
 
 -                 else if (num2<0)
 
 -                         throw new FuShuTwoException();
 
 -                 return num1/num2;
 
 -         }
 
 - }
 
 - //规定被除数不能为负数
 
 - class FuShuException extends Exception
 
 - {
 
 - }
 
 - //除数不能为负数
 
 - class FuShuTwoException extends Exception
 
 - {
 
 - }
 
  复制代码 
 
 |