Catching a generic exception
问题 Problem I am writing a Result type in Java, and I have found a need for it to have a method that performs an operation which may fail, and then encapulates the value or exception in a new Result object. I had hoped this would work: @FunctionalInterface public interface ThrowingSupplier<R, E extends Throwable> { R get() throws E; } public class Result<E extends Throwable, V> { ... public static <E extends Throwable, V> Result<E, V> of(ThrowingSupplier<V, E> v) { try { return value(v.get()); }