Question: I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help. 

```
class Main 
{  
    public static void main(String [] args) 
    {
        try 
        {
            badMethod();  
            System.out.print("A"); 
        }  
        catch (Exception ex) 
        {
            System.out.print("B");  
        } 
        finally 
        {
            System.out.print("C"); 
        } 
        System.out.print("D"); 
    }  
    public static void badMethod() throws Exception
    {
        throw new Exception(); /* Line 22 */
    } 
}

```

Answer: 
There is nothing to cause the program to exit.

The whole point of a `catch` block is to *catch* the exception and prevent it from propagating further.  

After catching an exception, execution continues.
Finally is called at the end of a try/catch block. It gets called even if the try fails and the catch is executed. The `Finally`block itself is only not executed if the program is killed somehow (JVM dies, forced to close, etc.)

In your example D is executing because it is outside of the try/catch/finally{} blocks.

There is a nice blog post on catching exceptions and the try/catch/finally behaviour [here](http://tutorials.jenkov.com/java-exception-handling/basic-try-catch-finally.html).