Method signature with checked exception

A method signature can end with a throws clause followed by one or more exception types that the method can throw. A ‘checked exception’ is an exception that is derived from the class (or is in fact an instance of) Exception.
A checked exception is not mandatory but should be declared in a method signature in the following cases:

– The ‘throw’ keyword is used to throw the exception in the method.
– Another method that throws the specific exception is called within the current method and the try / catch statements are not used.

If a method throws more than one exception the exception names are separated by commas.

An unchecked exception is derived from the class ‘Error’. Both the Exception and Error classes are derived from the super class ‘Throwable’.

Here are a couple of examples of how to use the throws clause in a method:

Search for more Java info on this site here:
Custom Search

Please type any questions here.