Mega Code Archive

 
Categories / Java / Language Basics
 

Finally is always executed

// : c09:AlwaysFinally.java // Finally is always executed. // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. class FourException extends Exception { } public class AlwaysFinally {   public static void main(String[] args) {     System.out.println("Entering first try block");     try {       System.out.println("Entering second try block");       try {         throw new FourException();       } finally {         System.out.println("finally in 2nd try block");       }     } catch (FourException e) {       System.err.println("Caught FourException in 1st try block");     } finally {       System.err.println("finally in 1st try block");     }   } } ///:~