What is the purpose of throw keyword? What happens if we write “throw null;” statement in a Java program?

Throw keyword is used to re-throw an exception which has been caught in a catch block. The syntax is “throw e;” where e is the reference to the exception being caught. The exception is re-thrown to the client.
This keyword is useful when some part of the exception is to be handled by the caller of the method in which throw keyword is used.

The use of “throw null;” statement causes NullPointerException to be thrown.

The answers are brief. Do post your comments if you think I have missed anything or discuss any other exception handling question.


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email