static void checkException(Exception e, String errmsg) {
    if (errmsg != null) {
      if (!e.getMessage().equals(errmsg)) {
        System.out.println("Expecting exception '" + errmsg + "' but got '"
            + e.getMessage() + "'");
        e.printStackTrace();
        (new Throwable()).printStackTrace();
        System.exit(1);
      }
    } else {
      System.out.println("Unexpected exception '" + e.getMessage() + "'");
      e.printStackTrace();
      (new Throwable()).printStackTrace();
      System.exit(1);
    }
  }