Write a program in java to demonstrate re-throwing exception?

class Divide

{

      public static int divide(int x,int y)

      {

            try

            {

                  return x/y;

            }

            catch(ArithmeticException e)

            {

                  System.out.println("Arithmetic Exception Caught In Divide, Rethrowing _ _ _ ");

                  throw(e);

            }

      }

      public static void main(String arg[])

      {

            try

            {

                  int a=Integer.parseInt(arg[0]);

                  int b=Integer.parseInt(arg[1]);

                  int c=divide(a,b);

                  System.out.println("Result is : "+c);

            }

            catch(Exception e)

            {

                  System.out.println("Vikrant Kumar");

                  System.out.println(e);

            }

      }

}

Rethrowing Exception.PNG

, , , , , , ,

Leave a Reply