Checked Exceptions-enabled Java 8+ functional interfaces + adapters
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Checked Exceptions-enabled Java 8+ functional interfaces + adapters

Build Status License

Provides shortcuts for solving Java 8 checked exceptions lambda repackaging hell.

You can define functions that throw checked exceptions:

ThrowingFunction<String, URI, URISyntaxException> toUri = URI::new;

And use those functions seamlessly with native java.util.function classes by using a custom ThrowingFunction#unchecked adapter:
  .map(unchecked(URI::new)) // static import of ThrowingFunction#unchecked

No more: -> {
     try {
         return new URI(path);
     } catch (URISyntaxException e) {
         throw new RuntimeException(e);

For Maven users:


For Gradle users:

compile 'pl.touk:throwing-function:1.3'

Available types:

Additional features:

default Function<T, R> uncheck() {...}

Transforms a ThrowingFunction instance into a regular Function. Checked exceptions get wrapped in a RuntimeException. Feature is available for all java.util.function types. Comes both as a static and as an instance method.

static Function<T, R> uncheck(ThrowingFunction<> f) {...}

Static version of the uncheck() method. Works nice when using with original java functional types.;

static Function<T, Optional<R>> lifted() {...}

Transforms ThrowingFunction into a regular Function returning result wrapped into an Optional instance. If exception is thrown, result will contain an empty Optional instance. Exception gets ignored. Comes as a static method. Equivalent instance method is called lift()

default ThrowingFunction<T, Void, E> asFunction() {...}

Returns ThrowingPredicate/ThrowingSupplier/ThrowingConsumer instance as a new ThrowingFunction instance.


Additional static function allowing catching wrapped checked exceptions, unwrap and rethrow them. Comes in handy sometimes.