| Difference between throw and throws in Java?
Throw is mainly used to actually throw an instance of class java.lang.Throwable. Which means we can throw Error and Exception both by using throw keyword. Below is the example to throw error:-
throw new IllegalArgumentException("Incorrect input values")
And when we talks about throws it is used as part of method declaration and signals which kind of exceptions are thrown by this method so that its caller can handle them. And in throws we must declare any unhandled checked exception in throws clause in Java. | | |