Amazon Interview Question
Software Engineer / DevelopersCountry: United States
It is generally used to close any db connections or remove any object references that are no longer used after the method exits.
Finally block is executed even if there is an exception in the method.
The only time 'finally' block is not executed is if System.exit(0) is called in the try/catch block.
One thing to add is that if exception occur and you return something from catch block, but still the function will return value from finally block if any.
- Muhammad Khojaye April 10, 2012