Home » java » Java Throws Keyword

Java Throws Keyword

In a java programming, throws keyword list the type of exception that a method might throw.

In the throws clause, we declare all the exception that a method can throw.

  Syntax:         

                                               

Here, exception1, exception2 are comma, list of the exception that a method can throw.

Example:

Explaination: We throws NullPointerException in the line “throw new NullPointerException(“demo”);” .

Here we set “demo” is a name of thread.

This line “throw new NullPointerException(“demo”);” throw the exception which is handled by catch block associated with try within main().

Managed by MochaHost - Fast & Easy WordPress Hosting