Skip to content


Folders and files

Last commit message
Last commit date

Latest commit


Repository files navigation

Checked-Exceptions-enabled Java 8+ Functional Interfaces

and adapters

Build Status License Maven Central


Standard java.util.function Functional Interfaces aren't checked-exception-friendly due to the absence of throws ... clause which results in tedious and verbose necessity of handling them by adding try-catch boilerplate.

Which makes one-liners like this:

path -> new URI(path)

become as verbose as:

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

By applying com.pivovarit.function functional interfaces, it's possible to regain clarity and readability:

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

and use them seamlessly with native java.util.function classes by using custom ThrowingFunction#unchecked adapters:
  .map(unchecked(URI::new)) // static import of ThrowingFunction#unchecked

which avoids ending up with: -> {
     try {
         return new URI(path);
     } catch (URISyntaxException e) {
         throw new RuntimeException(e);

Basic API

Functional Interfaces


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

Transforms a ThrowingFunction instance into a standard java.util.function.Function by wrapping checked exceptions in a RuntimeException and rethrowing them.

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

Transforms a ThrowingFunction instance into a regular Function returning result wrapped in an Optional instance.

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

Returns Throwing(Predicate|Supplier|Consumer) instance as a new ThrowingFunction instance.

Maven Central

compile 'com.pivovarit:throwing-function:1.5.1'


None - the library is implemented using core Java libraries.

Version history

1.5.1 (06-05-2020)

  • Fixed visibility issues with ThrowingIntFunction

1.5.0 (26-01-2019)

  • Introduced proper Semantic Versioning
  • Introduced ThrowingIntFunction
  • Moved interfaces to com.pivovarit.function
  • Removed controversial unwrap() functionality