if(e instanceof ExceptionA){
if(e instanceof ExceptionC){
System.err.println("Got ExceptionC instance:"+getMessage());
}else{
System.err.println("Got ExceptionA instance:"+e.getMessage());
}
}else if(e instanceof ExceptionB){
System.err.println("Got ExceptionB instance:"+e.getMessage());
}

解决方案 »

  1.   

    就是普通的if-else逻辑吧。。if-else是和最邻近的搭配的,看{ }仔细点就好if(e是否是ExceptionA的实例){
    if(e是ExceptionA的实例,再判断是否是ExceptionC的实例){  
    System.err.println("Got ExceptionC instance:"+getMessage()); //是ExceptionA和ExceptionC的实例
    }else{
    //是ExceptionA实例,但不是exceptionC的实例
    System.err.println("Got ExceptionA instance:"+e.getMessage()); 
    }
    }else if(e不是A的实例,再判断是否是ExceptionB的实例){
    System.err.println("Got ExceptionB instance:"+e.getMessage());
    }
      

  2.   


    if(e instanceof ExceptionA)
    {
         if(e instanceof ExceptionC)
          {
                System.err.println("Got ExceptionC instance:"+getMessage());
          }
          else
          {
                System.err.println("Got ExceptionA instance:"+e.getMessage());
          }
    }
    else if(e instanceof ExceptionB)
    {
          System.err.println("Got ExceptionB instance:"+e.getMessage());
    }相当于if(i<10)
    {
           if(i<5)
           {
                  System.out.println("i<5");
           }
           else
           {
                  System.out.println("i>5 and i,10");
           }
    }
    else if(i<20)
    {
           System.out.println("i>10  and i<20");
    }
    这样看清晰一些.
      

  3.   


    if (e instanceof ExceptionA) {
    if (e instanceof ExceptionC) {
    System.err.println("Got ExceptionC instance:" + getMessage());
    } else {
    System.err.println("Got ExceptionA instance:" + e.getMessage());
    }
    } else if (e instanceof ExceptionB) {
    System.err.println("Got ExceptionB instance:" + e.getMessage());
    }
    调一下格式 多清楚啊 就两个if吗
      

  4.   

    记住else 跟最近的 if 搭配就行了
      

  5.   

    给代码一些适当的缩进就行了  这个逻辑应该不难啊先判断异常是否是A类异常,如果是就进一步判断是否是A类里面的C类或者其他类,如果是就输出相应语句。
    如果异常不是A类异常,就再判断异常是不是B类异常,如果是就输出相应语句。
      

  6.   

    好好看一下ifelse的相关的东西呗