|
Re: Exception Handling
|
Posted: Jan 18, 2004 2:59 AM
|
|
It is throwing a compile time error because of the way java deals with casting.
maybe this will explain it.
public void something(){
List list = getArrayList();
ArrayList list2 = (ArrayList)getArrayList();
}
public List getArrayList(){
ArrayList list = new ArrayList();
return list;
}
the ArrayList is getting put into a list when it leaves getArrayList. So in something() putting it into a list is fine (upcasting is always safe). This is what you're doing with your exception. You are throwing a blueexception upcasting it to a whiteexception in m1().
So the second time I get the ArrayList I try to place it into an ArrayList but I get a compile time error because I am downcasting, in which case I have to cast it.
So you are getting a compile time error for the same reason. You cast it to a whiteexception in which case you have to catch that or a super class of it.
Jonathon
|
|