Finally block inside a method should execute before the method returns or throws an exception.
A most common use of finally block is to close the jdbc connection object.
where conn is the reference to the connection object.
But now imagin what will happen if method returned before finally got executed. --> There will be no conn reference available to finally block because the local stack variables for the method would be gone.
So it is quite logical to think that finally block should be executed before method returns or throws exception.
mohitkumar gupta wrote:i didn't get it.
why is the finally block executing after catch?
Because the catch is in a completely different method. Once you're outside fnA, you're outside it. The finally block will be the last thing that happens inside fnA, but the catch doesn't happen till you've left it.