Difference Between throw and throws in Java

The throw and throws are the two keywords used in exception handling. In this article, you will learn about how both of them are different from one another.

Difference Between throw and throws in Java

ThrowThrows
This keyword is used for explicitly throwing an exception.This keyword is used for declaring any exception.
Programmers cannot disseminate checked exceptions using throw keyword.Programmers can disseminate checked exceptions using throws keyword.
An instance trails the throw keyword.A class trails the throws keyword.
You have to use the throw keyword inside any method.You have to use the throws keyword with any sign of the method.
Multiple exceptions cannot be thrown.Multiple exceptions can be declared using the throws.
Code Snippet:

Class Example
{
public static void main(String argu[])
{
throw new ArithmeticException("Divided by zero");
}
}

Code Snippet:

public void testExc() throws SQLException , IOException


Courses
Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.