
143 Java Functional Exception Handling
This is a solid refactoring guide that moves Java codebases away from exception-heavy control flow toward Optional and VAVR Either types for predictable failures. It's opinionated about reserving exceptions for actual system failures, not business logic like "user not found." The workflow is safety-first: it forces you to run mvn validate before touching anything and verify afterward. You get concrete good/bad examples for sealed error hierarchies, monadic composition with flatMap, and structured logging discipline. It's part of the cursor-rules-java project and assumes you're comfortable with functional patterns. Use it when your codebase treats exceptions as goto statements and you want clearer error contracts.
- skills.sh installs
- 133
- GitHub stars
- 393
- last updated
- Jun 3, 2026
Install
$ npx -y skills add jabrena/cursor-rules-java --skill 143-java-functional-exception-handling --agent claude-codeInstalls into .claude/skills of the current project.
Files
Java Functional Exception handling Best Practices
Identify and apply functional exception handling best practices in Java to improve error clarity, maintainability, and performance by eliminating exception overuse in favour of monadic error types.
What is covered in this Skill?
Optional<T>for nullable values over throwingNullPointerExceptionorNotFoundException- VAVR
Either<L,R>for predictable business-logic failures CompletableFuture<T>for async error handling- Sealed classes and records for rich error type hierarchies with exhaustive pattern matching
- Enum-based error types for simple failure cases
- Functional composition:
flatMap/map/peek/peekLeftfor chaining operations that can fail - Structured logging: warn/info for business failures, error for system failures
- Checked vs unchecked exception discipline
- Exception chaining with full causal context when exceptions are unavoidable
Scope: The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.
Constraints
Sponsors
Details
- Repository
- github.com/jabrena/cursor-rules-java
- Categories
- Debugging, Java & JVM
- First seen
- Jun 3, 2026
More from jabrena/cursor-rules-java
All 16- 122 Java Type Design132
- 144 Java Data Oriented Programming129
- 170 Java Documentation129
- 132 Java Testing Integration Testing128
- 113 Java Maven Documentation125
- 110 Java Maven Best Practices160
- 121 Java Object Oriented Design153
- 124 Java Secure Coding146
- 111 Java Maven Dependencies136
- 125 Java Concurrency135
- 128 Java Generics135
- 141 Java Refactoring With Modern Features135
- 142 Java Functional Programming135
- 131 Java Testing Unit Testing134
- 112 Java Maven Plugins133