code: public static void fireFirstDeclared(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;
              }
          }
          throw new UndeclaredThrowableException(t);
      }
docs: Throws the either the original exception or the first found cause if it
  matches one of the given declared types or is unchecked. Otherwise, the
  original exception is thrown as an UndeclaredThrowableException. 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.