Declaring Exceptions in Java Programming

Declaring Exceptions in Java Programming

Previous Home Next

 

If it is not appropriate for your method to catch and handle an exception thrown by a method that it calls, or if your method itself throws its own exception, you must declare in the method signature that the method throws the exception.


 

If the List() method doesn't catch the exceptions that can occur within it, then the List() method must declare that it can throw them. Let's modify the List() method to declare the methods that it can throw. 

 
public void List() throws IOException, ArrayIndexOutOfBoundsException {

Previous Home Next