Throws in exception handling in java

Throws keyword in java is used to declare exceptions that can be thrown by the method. Throws keyword can be used to throw multiple exception.


1. Throws single exception


2. Throws multiple exception



When a method throws an exception, the code that uses this method needs to handle this exception.
Handling of exception can be of 2 types
1. Use a Try-Catch block
2. Use throws method to again throw the same or new exception.

Lets see an example where we have a method convertListToString that throws exception.
In main method we call the convertListToString and also handle the exception that was thrown.

Example : Throws in exception handling