If the method is declared to throw the same exceptions thrown by some code and that code is also enclosed in a try/catch, will the exception be caught by the catch or will the error still be thrown? I am guessing that the catch has precedence although I am not 100% sure.
If I understand you correctly, you are asking:
void someMethod() throws SomeException {
try {
doSomethingElse()
} catch (SomeException e) {
// is this reached or does it throw from the method?
}
}
The catch clause will be triggered and the exception is considered handled. Unless you re-throw it from that block, it will not escape the method.
In my example, there is no need for your method to declare that it throws SomeException
, because it doesn't.