code: public static Throwable getCause(Throwable e, Class<? extends Throwable>... causes) {
          if ((e == null) || (causes == null) || (causes.length < 1)) {
              return null;
          } else if (isInstance(e, causes)) {
              if (((e.getCause() == null) || (e.getCause()
                      .equals(e) || (!equals(e.getClass(), causes))))) {
                  return e;
              } else {
                  return getCause(e.getCause(), causes);
              }
          } else if ((e.getCause() == null) && (e instanceof InvocationTargetException)) {
              return getCause(((InvocationTargetException) e).getTargetException(), causes);
          } else if (e.getCause() == null) {
              return null;
          } else {
              return getCause(e.getCause(), causes);
          }
      }
docs: Gets the cause which are one of the given expected causes. This method is
  useful when you have to find a cause within unexpected or unpredictable
  exception wrappings.
  
  @param e      the exception instance to search the cause on
  @param causes the causes which are searched.
  @return the found cause, where the first occurring cause instance will be returned. If
  the cause could not be found, then null will be returned