Login    New User    Forgot Password    Help      

Throws in Java

Java Tutorials

// Throws
// Throws clause lists the types of exceptions that a method might throw.

class  ex5
{
static void excall() throws IllegalAccessException
      {
        System.out.println("Inside the function ");
        throw new IllegalAccessException(" Illegal Access ");
      }

public static void main(String args[])
 {
        try
          {
          excall();
          }
        catch(IllegalAccessException e)
         {
          System.out.println("Caught  " +  e);
          }
 }
}

 

Output

Java Tutorials