1.

What Is Throw Keyword?

Answer»

It is POSSIBLE for a Java program to throw an exception explicitly that is done using the throw statement.

The general form of throw is - 

throw throwableObject;

We can get this throwableObject in 2 ways -

  • By using the Exception parameter of catch block.
  • CREATE a NEW ONE using the new operator.

    try{
    throw new NULLPOINTEREXCEPTION();
    }catch(NullPointerException nExp){
    System.out.println("Exception caught in catch block of displayValue");
    throw nExp;
    }
    }

It is possible for a Java program to throw an exception explicitly that is done using the throw statement.

The general form of throw is - 

throw throwableObject;

We can get this throwableObject in 2 ways -



Discussion

No Comment Found