Wednesday, 8 November 2017

Difference between throw and throws in java || Throws || Throw

 

  Difference Between Throw And Throws


There are many differences between throw and throws keywords. A list of differences between throw and throws are given below:

Throw



The throw keyword is used to explicitly throws an exception.

Checked exception cannot be propagated using throw only.

The throw is followed by an instance.

The throw is used within the method.

You can't throw multiple exceptions.

Throws

 

Java throws keyword is used to declare an exception.

Checked exception can be propagated with throws.

The throws is followed by class.

The throws is used with the method signature.

You can declare multiple exceptions e.g.
public void method()throws IOException,SQLException.

 

Popular posts