All pages
Powered by GitBook
1 of 1

Loading...

Introduction

A Java library to handle success and failure without exceptions

Handle success and failure in Java without exceptions

Wave goodbye to slow exceptions and embrace clean, efficient error handling by encapsulating operations that may succeed or fail in a type-safe way.

rocket-launchStart here Fork me on GitHub

Result is a Java library for modeling operation outcomes explicitly. It gives you a simpler, faster alternative to exception-driven flow when you want to represent both success and failure in a single, composable type.

Why Result?

Optional is great for values that may be present or absent, but it does not explain why something is missing. Result fills that gap by carrying either a successful value or a failure reason, so your code can describe what happened instead of hiding it.

Mental Model

Quick Start

1

Create a result from an operation

2

Inspect whether it succeeded or failed

3

Transform it if needed, then unwrap it as required

Available in

Integrate Result with popular libraries.

Try it for yourself in 5 minutes.

Read the guide and transform your error handling today.

Also available as an ebook in multiple formats.

Not a fan of reading long docs? No worries! Tune in to Deep Dive, a podcast generated by . In just a few minutes, you'll get the essential details and a fun intro to what this library can do for you!

Result<User, Exception> result = Results.ofCallable(() -> db.getUser(id));
result.ifFailure(error -> logger.error("Couldn't get user: {}", id, error));
String name = result.mapSuccess(User::name).orElse("Anonymous");
<dependencies>
    <dependency>
        <groupId>com.leakyabstractions</groupId>
        <artifactId>result</artifactId>
        <version>1.0.0.0</version>
    </dependency>
</dependencies>
dependencies {
    implementation("com.leakyabstractions:result:1.0.0.0")
}

Latest Releases

Add-Ons

Demo Projects

Features

Ready to Tap into the Power of Results?

TL;DR

🌱Getting Started
🪴Basic Usage
🚀Advanced Usage
Download your free copy now!
NetbookLM

Works with

Works with

Assert results fluently with

Serialize results to JSON with

Works with

Works with

Boost Performance

Avoid exception overhead and benefit from faster operations

Simple API

Leverage a familiar interface for a smooth learning curve

Streamlined Error Handling

Handle failure explicitly to simplify error propagation

Safe Execution

Ensure safer and more predictable operation outcomes

Enhanced Readability

Reduce complexity to make your code easier to understand

Functional Style

Embrace elegant, functional programming paradigms

Lightweight

Keep your project slim with no extra dependencies

Open Source

Enjoy transparent, permissive Apache 2 licensing

Pure Java

Seamless compatibility from JDK8 to the latest versions

Maven Central repository
Maven
Maven
Gradle
Gradle
AssertJ
AssertJ
Jackson
Jackson
Spring Boot
Micronaut
Micronaut
Because exceptions are so last century.
Because exceptions are so last century.
For a smooth ride from Optional to Result.
For a smooth ride from Optional to Result.
Say goodbye to error-handling acrobatics.
Say goodbye to error-handling acrobatics.
Skip the exception rollercoaster and enjoy the smooth ride.
Skip the exception rollercoaster and enjoy the smooth ride.
So you can actually understand your own code next month.
So you can actually understand your own code next month.
For those who prefer elegance over chaos.
For those who prefer elegance over chaos.
Because bloated libraries are so overrated.
Because bloated libraries are so overrated.
Feel free to tweak and share — no strings attached.
Feel free to tweak and share — no strings attached.
Whether you're stuck in the past or embracing the future, we've got you covered.
Whether you're stuck in the past or embracing the future, we've got you covered.