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(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(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());
}
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");
}
这样看清晰一些.
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吗
如果异常不是A类异常,就再判断异常是不是B类异常,如果是就输出相应语句。