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

What is the Purpose of Spring Configuration File ?

What is a Directive in JSP ?

Comparing HashSet and TreeSet Collections in Java

When Do You Use Exception or Error in Java ?

Why Do You Use Upcasting or Downcasting in Java ?