Skip to content

Instantly share code, notes, and snippets.

@fge
Created March 4, 2015 12:04
Show Gist options
  • Select an option

  • Save fge/5a5fbf647d1624c3d1e0 to your computer and use it in GitHub Desktop.

Select an option

Save fge/5a5fbf647d1624c3d1e0 to your computer and use it in GitHub Desktop.
package com.github.fge.lambdas.function;
import com.github.fge.lambdas.ThrownByLambdaException;
import java.util.function.Function;
@FunctionalInterface
public interface ThrowingFunction<T, R>
extends Function<T, R>
{
R doApply(T t)
throws Throwable;
default R apply(T t)
{
try {
return doApply(t);
} catch (Error | RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new ThrownByLambdaException(throwable);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment