public static <T, R> Function<T, R> doAndHandle(final CheckedFunction<T, R> function,
                                                    final CheckedFunction<Throwable, R> errorHandler) {
        return t -> {
            try {
                return function.apply(t);
            } catch (final Throwable e) {
                try {
                    LoggingUtils.warn(LOGGER, e);
                    return errorHandler.apply(e);
                } catch (final Throwable ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }
        };
    }
Default function function.

@param <T>          the type parameter
@param <R>          the type parameter
@param function     the function
@param errorHandler the error handler
@return the function
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/function/FunctionUtils.java