A Java library to handle success and failure 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.
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.
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.
Create a result from an operation
Result<User, Exception> result = Results.ofCallable(() -> db.getUser(id));Inspect whether it succeeded or failed
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.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")
}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