Java Exception Handling (Try-catch)

  • + 0 comments

    Here is my code...

    import java.util.*;
    public class solution
    {
        public static void main(String[] args)
        {
            Scanner scan=new Scanner(System.in);
            try
            {
                int a=scan.nextInt();
                int b=scan.nextInt();
                System.out.println(a/b);
            }
            catch(InputMismatchException e)
            {
                System.out.println("java.util.InputMismatchException");
            }
            catch(Exception e)
            {
                System.out.println(e);
            }
        }
    }
    

    Instead of printing java.util.InputMismatchException I got java.util.InputMismatchException: For input string: "2147483648" ,So I made another catch to directly print the exception