1. Use of Throw and Throws

Throw keyword is used to throw an exception explicitly.

Throws clause is used to declare an exception, which means it works similar to the try-catch block.

2. Method Flexibility

Throw keyword is used in the method body to throw an exception.

while throws is used in method signature to declare the exceptions that can occur in the statements present in the method.

3. Representation of Syntax

If we see syntax wise then throw is followed by an instance variable

while throws is followed by exception class names.

For example:

throw new ArithmeticException(“Arithmetic Exception”);

and

throws ArithmeticException;

4. Multiple Exceptions.

You cannot throw multiple exceptions.

But you can handle multiple exceptions by declaring them using throws keyword.

It's good to share...Share on FacebookTweet about this on TwitterShare on LinkedInPin on PinterestShare on Google+Email this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *