code: public static void fireFirstDeclaredCause(Throwable t, Class... declaredTypes) {
          Throwable cause = t;
          while (cause != null) {
              cause = cause.getCause();
              if (cause == null) {
                  break;
              }
              if (declaredTypes != null) {
                  for (Class declaredType : declaredTypes) {
                      if (declaredType.isInstance(cause)) {
                          fire(cause);
                      }
                  }
              }
              if (cause instanceof RuntimeException) {
                  throw (RuntimeException) cause;
              }
              if (cause instanceof Error) {
                  throw (Error) cause;
              }
          }
          fireDeclaredCause(t, declaredTypes);
      }
docs: Throws the first found cause that matches one of the given declared
  types or is unchecked. Otherwise, the immediate cause is thrown as an
  UndeclaredThrowableException. If the immediate cause is null, then the
  original exception is thrown. This method only returns normally if the
  exception is null.
  
  @param t exception whose cause is to be thrown
  @param declaredTypes if exception is checked and is not an instance of
  any of these types, then it is thrown as an
  UndeclaredThrowableException.