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: 
The `finally` block doesn't finalize the program, it just ensure to execute every time the try catch block runs whereas there is an exception or not..
It would print `BC` if you re-throw the exception in `catch` block.

```
catch (Exception ex) 
{
    System.out.print("B");  
    throw ex;
}

```

Then you'll have to declare your main as 

```
public static void main(String [] args) throws Exception

```