Showing posts with label reference :: http://www.javawithus.com/tutorial/nested-try-catch-blocks. Show all posts
Showing posts with label reference :: http://www.javawithus.com/tutorial/nested-try-catch-blocks. Show all posts

Tuesday, May 7, 2019

nested try



import java.util.*;
public class p1 {
    public static void main(String[] args) {
        try {
            System.out.println("Outer try block starts");
            try {
                System.out.println("Inner try block starts");
                int res = 5 / 0;
            } catch (InputMismatchException e) {
          System.out.println("InputMismatchException caught");
            } finally {
                System.out.println("Inner final");
            }
        } catch (ArithmeticException e) {
            System.out.println("ArithmeticException caught");
        } finally {
            System.out.println("Outer finally");
        }
    }
}






C:\Users\Com science\Documents>java p1
Outer try block starts
Inner try block starts
Inner final
ArithmeticException caught
Outer finally

C:\Users\Com science\Documents>