Java-Finally Statement

Finally Statement

Java supports another statement knows as finally statement. The JVM ensures that the statements placed in the finally block are executed whether or not an exception occurs. So, even if no exception occurs during the execution of a try block, the finally block is executed. When an exception occurs, an appropriate catch block will be executed. Then, the finally block will also be executed. The finally block is optional. Remember that each try block should be followed by at least one catch block or a finally block.



Program Source

class Javaapp {

    public static void main(String[] args) {
            int a=1/0;
        }catch(ArithmeticException ex)
            System.out.println("Exception : "+ex);
            System.out.println("I Am Finally");
        System.out.println("Execution Complete");

Leave a Comment