public static <T> ToDoubleFunction<T> toDoubleFunction(CheckedToDoubleFunction<T> function, Consumer<Throwable> handler) {
        return t -> {
            try {
                return function.applyAsDouble(t);
            }
            catch (Throwable e) {
                handler.accept(e);

                throw new IllegalStateException("Exception handler must throw a RuntimeException", e);
            }
        };
    }
public static < T > ToDoubleFunction < T > toDoubleFunction ( CheckedToDoubleFunction < T > function , Consumer < Throwable > handler ) { return t -> { try { return function . applyAsDouble ( t ) ; } catch ( Throwable e ) { handler . accept ( e ) ; throw new IllegalStateException ( "Exception handler must throw a RuntimeException" , e ) ; } } ; }
Wrap a {@link CheckedToDoubleFunction} in a {@link ToDoubleFunction} with a custom handler for checked exceptions.
<p>
Example:
<code><pre>
map.forEach(Unchecked.toDoubleFunction(
k -> {
if (k.length() > 10)
throw new Exception("Only short strings allowed");

return 42.0;
},
e -> {
throw new IllegalStateException(e);
}
));
</pre></code>