Join Webinar on "Exception Handling in Java 7" by Mala Gupta-author of Manning's bestseller "OCA Java SE 7 Programmer I Certification Guide" on 8 November 8:30 AM IST.
Here's an interesting way to remember that a finally block will execute irrespective of whether an exception is thrown by the try block (from the book):
Imagine a guy promises to buy diamonds for his girlfriend and treat her to coffee. The girl inquires about what will happen if he meets with an exceptional condition during the diamond purchase, such as inadequate funds. To the girl’s disappointment, the boy replies that he’ll still treat her to coffee. Compare the try block to the purchase of diamonds and the finally block to the coffee treat. The girl gets the coffee treat regardless of whether the boy successfully purchases the diamonds.