If the finally block terminates abruptly like with a return statement, then if there was a return statement executed in the try block or in one of the catch blocks, that statement is ignored, and the try-catch-finally ends for the reason the finally ended.
Originally posted by raminaa niilian: I am just wondering why should the finally block execute even if i return from the method in try block ?
Well, because that's exactly what it is meant to be used for: executing code that should *always* be executed when the try block ends. Common use is freeing resources that have been in use, such as streams, database connections etc. When you are done with them, you typically want to release them no matter what.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database