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

How Can We Improve the Performance of IdentityHashMap in Java ?

Why Java Does Not Support Operator Overloading ?

How HashMap Works in Java ?

Java How To Find The Average Of 10 Numbers Using A While Loop

What is the Purpose of Properties File in Java ?