Hi,
I am a little confused with the following code:
In the above method even though we are throwing an exception it does not have to be declared in the method signature
because the return statement is in the finally block.
However if we put the return statement outside the finally block:
this code will not compile because the InterruptedException needs to be declared in the method signature.
Could anyone please let me know why the first method compiles?
From what I understand about exception handling - if a method throws an exception then it must be declared.
I'm guessing that if the return statement is in the finally block that the int returned is taking precedence over the exception being thrown since finally block is always executed???
Many Thanks
I am a little confused with the following code:
In the above method even though we are throwing an exception it does not have to be declared in the method signature
because the return statement is in the finally block.
However if we put the return statement outside the finally block:
this code will not compile because the InterruptedException needs to be declared in the method signature.
Could anyone please let me know why the first method compiles?
From what I understand about exception handling - if a method throws an exception then it must be declared.
I'm guessing that if the return statement is in the finally block that the int returned is taking precedence over the exception being thrown since finally block is always executed???
Many Thanks