Feedback on checked exceptions and lambdas

Published: (February 5, 2026 at 04:02 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Cover image for “Feedback on checked exceptions and lambdas”

I got a lot of interesting feedback on the article Checked exceptions and lambdas.
Let’s start with my own: after writing that post I realized I had already written a similar post some time ago.

Mistakes I made

I mixed up Apache Commons Lang 3 with Vavr.
I used the recover() function, which belongs to Vavr, while Apache Commons Lang only provides regular utility methods.

Vavr’s Try class encapsulates methods that throw checked exceptions and bridges Java to a more functional style.

var foo = new Foo();
CheckedFunction1 throwingFunction = foo::throwing;

var result = List.of("One", "Two")
    .stream()
    .map(input ->
        Try.of(() -> throwingFunction.apply(input))
            .recover(IOException.class, e -> "")
            .getOrElse("")
    )
    .toList();

Vavr’s API is quite large, but Try itself has a fairly understandable surface:

Vavr’s Try class diagram

Things I forgot

On Mastodon, Oliver Drotbohm pointed out that the Spring Framework provides its own wrapping utilities.

Spring logo
Oliver Drotbohm: “@frankel@mastodon.top If you happen to build a Spring‑based application, there are a few helpers, too: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/function/package-summary.html”

Spring utilities that wrap exceptions

Things I learned

Another piece of feedback mentioned Result4J, a library I hadn’t heard of before.

Result4J provides a Rust‑like Result type that can represent either a successful value or an error. While Java’s native way of reporting errors is via exceptions, a Result type can be handy in functional‑style code where pure functions are expected to throw no exceptions.

  • Repository:
  • Maven artifact: io.github.sviperll:result4j

Example (from the README)

Catcher.ForFunctions io = Catcher.of(IOException.class).forFunctions();

String concatenation = Stream.of("a.txt", "b.txt", "c.txt")
    .map(io.catching(name -> loadResource(name)))
    .collect(ResultCollectors.toSingleResult(Collectors.join()))
    .orOnErrorThrow(Function.identity());

Result4J API overview

Additional feedback

On Bluesky, Donald Raab (former designer of Eclipse Collections) shared a post about how Eclipse Collections handles checked exceptions.

“Thanks for sharing! I wrote the following blog about Exception Handling in Eclipse Collections a few years ago. There’s also a link to a great blog from @brianvermeer.nl in there. 🙏”

You can read the post here:

— Donald Raab (@thedonraab.bsky.social) 2026‑01‑18 19:30 UTC

Conclusion

Feedback is always great. Thanks to feedback, I realized I made a mistake, received pointers to the same features in Spring, and discovered result4j. Having coded for years in Kotlin and more recently in Rust made me appreciate the Result approach. I’ll evaluate the usage of result4j as an alternative to Vavr in future projects.

To go further

Originally published at A Java Geek on February 1st, 2026.

Back to Blog

Related posts

Read more »

My Java Notes: Understanding String

When working with Java programs, handling text is very common—storing names, messages, or user input. In Java, text is handled using the String class. What Is a...

Java Notes

Running Java from Terminal bash javac App.java && java App javac compiles the Java source file App.java into bytecode App.class. The && operator runs the secon...

SPRING BOOT EXCEPTION HANDLING

Java & Spring Boot Exception Handling Notes 1. What is Exception? Exception = unwanted situation that breaks normal flow of program. Goal of exception handling...