比如
public class Text{
int x = 1;
int y =-1;
public void a(){
try{
b();
}catch(Exception e){
}
}
public void b() throws NullPointerException,NegativeArraySizeException{
if(x<0)
throw new NullPointerException();
if(y>0)
throw new NegativeArraySizeException();
}
}
public class test{
public void setID()throws SQLException{ //此处创建了一个Exception对象
throw new SQLException("connection error!"); //此处又创建了一个Exception对象
}
}
当调用setID()时,不还是创建了两个Exception对象