Quote Originally Posted by Geek_Guest View Post
What is the purpose of finally block (i know Mandatory statements are written in finally block) but outside of the catch block statements are also executed right i write mandatory statements are written out side the catch block. so pls tell me finally block need?

Question asked by visitor Sudheer

The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.