Listing 4: File FinallyTest.java — Illustrates the behavior of finally blocks

class FinallyTest
{
    public static void f()
    throws Exception
    {
        try
        {
                                        // 0
            // return;                  // 1
            // System.exit(0);          // 2
            // throw new Exception();   // 3a
        }
        catch (Exception x)
        {
            // throw new Exception();   // 3b
        }
        finally
        {
            System.out.println("finally!");
        }

        System.out.println("last statement");
    }
 
    public static void main(String[] args)
    {
        try
        {
            f();
        }
        catch(Exception x)
        {}
    }
}
— End of Listing —