Difference between throw and throws in Java

It is one of the important questions in the interview room. There are numerous difference between throw and throws keywords. A list of differences between throw and throws are given underneath:

1)The main objective of throw keyword is to create exception object and handover to JVM, Sometimes programmer creates exception object programmatically and handover it to JVM for that throw keyword is required.Java throws keyword is used to declare an exception. Used for a declaration of exception which indicates the exception is thrown by a method.
2)Checked exception cannot be propagated using throw only.Checked exception can be propagated with throws.
3)Throw is followed by an instance.

throw new ArithmeticException(“Arithmetic Exception”);

Throws is followed by class.

throws ArithmeticException;

4)Throw is used within the method to throw an exception.

void m1() {
try {
//throwing arithmetic exception using throw
throw new ArithmeticException(“Number is not divisivle by 0!!”);
catch (Exception exp) {
System.out.println(“Error: “+exp.getMessage());

Throws are used with the method signature to declare an exception.

//Declaring arithmetic exception using throws void m2() throws ArithmeticException{ //Statements }

5)You cannot throw multiple exceptions.

void m1() { //Throwing single exception using throw throw new ArithmeticException(“An integer should not be divided by zero!!”); }

You can declare multiple exceptions e.g.

//Declaring multiple exceptions using throws void m2() throws ArithmeticException, NullPointerException{ //Statements where exception might occur }

6)throw keyword is used to throw user defined exception / customized exception.throws keyword is used to report the customized exception.

Throw –

Throws –