no-raise API in Java

Posted & filed under Java, Software Engineering.

I’ve been reading Exceptional Ruby by Avdi Grimm to get a different perspective on exception handling and was pleased to see he recommends what he calls namespaced exceptions. In Java this is just bundling your own Exception classes as part of the API:

public class MatrixException extends Exception {
}

public boolean doSomething(File theFile) throws MatrixException {
  try {
    ... do something with a file
  }
  catch(FileNotFoundException fnfe) {
    throw new MatrixException(fnfe);
  }
} (more...)