Looking for verification on the following:
In the implemented/overridden method, Java concerns itself ONLY with the checked exceptions declared to be thrown.
Eg.: To the interface:
interface INT { void mm() throws IOException, ArrayIndexOutOfBoundsException; }
,
class Some implements INT {
void mm() {...}
// ...
}
doesn't give a checked error. Neither does the following (since NullPointerException
is a RunimeException
):
class Some implements INT {
void mm() throws NullPointerException {...}
// ...
}
while
class Some implements INT {
void mm() throws ActivationException {...}
// ...
}
gives a compiler error since ActivationException
is a checked exception and its super-class implementation isn't throwing it (or a sub-class of it).
Note here:
class Some implements INT {
void mm() throws IndexOutOfBoundsException {...}
// ...
}
doesn't give a compile-time error although IndexOutOfBoundsException
is super to ArrayIndexOutOfBoundsException
since they are runtime exceptions.
Also note:
class Some implements INT {
void mm() throws Exception {...}
// ...
}
gives a checked error since Exception
can also be a checked exception and is super to those in the overridden one.
In the overall,
an exception declared to be thrown in the overriding method gets a compiler error ONLY IF it is a checked exception and it isn't (or a super-type of it isn't) thrown in the overridden method of its super class.
This is exception handling in the implemented method more elaborate and extensive. Asking it again-- couldn't get an answer there to its narrower version.
TIA.