What is the Difference Between Throw and Throws in Java ?

Java provides throw keyword to throw an exception from a method or a static block. Java provides throws keyword to mention the probable exception thrown by a method in its declaration.

We use throw to explicitly throw an exception. We used throws to declare an exception in method definition.

We cannot propagate checked exceptions with throw only. But checked exceptions can be propagated with throws keyword.

A throw call is followed by an instance. Class or Exception follows a throws keyword.

Call to throw occurs within a method. throws is just used with method signature.

We can throw only one exception at a time. But we can mention as many exceptions in throws clause.



You May Interest

Why Do We Use JSP Instead of Servlet in Java ?

Why Java Provides Garbage Collector ?

What is the Purpose of Native Method in Java ?

What is the Importance of hashCode and equals Methods in Java ?

What is Externalizable Interface in Java ?