Exception handling in stream

1
2
3
public interface ExceptionFunction<T, R> {
R apply(T t) throws Exception;
}
1
2
3
4
5
6
7
8
9
10
11
public class ExceptionUtil {
public static <T, R> Function<T, R> wrap(ExceptionFunction<T, R> f) {
return (T t) -> {
try {
return f.apply(t);
} catch (Exception e) {
throw new RuntimeException(e);
}
};
}
}
Share