public static <T extends Throwable> Optional<T> findCause(Throwable t, Class<T> clazz) {
        for (; t != null; t = t.getCause()) {
            if (clazz.isInstance(t))
                return Optional.of(clazz.cast(t));
        }
        return Optional.empty();
    }
Returns the first cause or the given throwable that is an instance of {@code clazz}
vespajlib/src/main/java/com/yahoo/yolean/Exceptions.java