Write a program in java to demonstrate throw and throws?

import java.io.IOException;

class ThrowsAndThrow

{

      void a() throws IOException

      {

            throw new IOException("Divice Error");

      }

      void b() throws IOException

      {

            a();

      }

      void c()

      {

            try

            {

                  b();

            }

            catch(Exception e)

            {

                  System.out.println("Exception Handled");

            }

      }

      public static void main(String arg[])

      {

            ThrowsAndThrow d=new ThrowsAndThrow();

            d.c();

            System.out.println("Normal Flow");

      }

}

Throw And Throws.PNG

, , , , , ,

Leave a Reply