Java-Nested Try Statements

Nested Try Statements

The try statement can be nested. There could be situations where is a possibility of generation of multiple exceptions of different types within a perticular block of the program code. We can use nested try statements in such situations.

Program


final

Program Source

class Javaapp {
    
    public static void main(String args[]) {
        
        try {
            
            try{
                int data[] = new int[5];
                data[6] = 200;
                
            }catch(ArrayIndexOutOfBoundsException ar)
            {
                System.out.println(ar);
            }
            
            int value = 200/0;
            
        }catch(ArithmeticException ae) {
           
            System.out.println(ae);
        }
    }
}

Leave a Comment