How to catch an exception thrown by a function?

When you declare a checked Exception in the signature of a method, you don’t need to handle it in this method. At the contrary, any method calling loader will have either to declare this Exception in its header or handling it in a try/catch block :

public void someMethod() throws IOException {
   loader(...);
}

// or

public void someMethod() {
   try {
     loader(...);
   } catch (IOException io) {
      //...
   }
}

Leave a Comment