Compare these two methods:
void foo() throws SomeSuperException {
try {
//...
} catch (SomeSuperException e) {
if (e instanceof SomeSubException) {
throw e;
}
}
}
void bar() throws SomeSubException {
try {
//...
} catch (SomeSuperException e) {
if (e instanceof SomeSubException) {
throw (SomeSubException) e;
}
}
}
Aside from the method signatures (bar can declare throws SomeSubException instead of throws SomeSuperException), is there any practical difference between the two methods?
To be clear: I’m aware that this is a horrible approach to exception handling, and should not be done!
The difference is that in the first case, externally the caller doesn’t know about your specific
SomeSubException, so some detail is lost in translation.