import java.io.Reader;
import java.io.FileReader;
import java.io.IOException;

public class ChainingExceptionExample {
  public static void doit(String fname) throws IllegalArgumentException {
    try {
      Reader r=new FileReader(fname);
      r.close();
    }
    catch (IOException e) {
      throw (IllegalArgumentException)(new IllegalArgumentException("Problem with file '" + fname + "'").initCause(e));
    }
  }

  public static void main(String args[]) {
    try {
      doit("splat");
    }
    catch (Exception e) {
      System.err.println("doit() died with exception e=" + e);
      System.err.println("e had cause: " + e.getCause());
      System.exit(1);
    }
  }
}
