Monica. Shiralkar wrote:if we have try catch finally , then instead of having finally if we write the code which should be in finally block without a finally block after catch, then also it will be executed in either case. So what is the benfit we got by using try catch finally instead of try catch.
Basically, your premise is incorrect. The finally block will execute, even if exceptions are thrown that are not caught (in cases where some exceptions are caught, but not others), or a return is executed in the try or catch blocks (which normally, mean that the code after the try-catch will not run). The finally block run when the try-catch completes, regardless of how it completes.