Interview Question
matching exception in java, is an exception-handling that looks for the nearest exception handler. Example:
Class Dodge extends Car{
public void someMethod throws Dodge(){
try{
throw new Dodge();
}catch(Car e){
}
public void getSomeMethod(){
try{
this.someMethod();
}catch(Dodge e){
//some code
}catch(Car e){
//some code
}
}
}
}
If you take the Dodge exception catch out of the second method. The Car exception would still be caught becuase it is the base class. This is useful because if you decide to add more exceptions to a method, if they’re all inherited from the same base class then the client programmer’s code will not need changing, assuming they catch the base class, at the very least.
I guess unmatched exceptions are when you do not have a base class or do not implement a catch for the base class.
This is Amazon 1st round
- Anonymous March 13, 2010