jabrena avatar

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-code

Installs 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 throwing NullPointerException or NotFoundException
  • 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/peekLeft for 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

Recommended

More Debugging
1erichowens avatarreactive-dashboard-performanceerichowens/some_claude_skillsreactive dashboard performance132skills.sh installs
2brianlovin avatarfix-sentry-issuesbrianlovin/claude-configfix sentry issues122skills.sh installs
3erichowens avatarreact-performance-optimizererichowens/some_claude_skillsreact performance optimizer118skills.sh installs
4agentworkforce avatardebugging-websocket-issuesagentworkforce/relayIf you've ever seen "RSV1 must be clear" or "Invalid frame header" errors and wondered why your WebSocket is receiving HTTP garbage,...0skills.sh installs
5butterbase-ai avatardebug-rlsbutterbase-ai/butterbase-skillsWhen your frontend users complain they can't see their data or they're seeing everyone else's data, this is the protocol to follow.0skills.sh installs
6cclank avatarseedance-debuggercclank/lanshu-awesome-ai-video-kit诊断 Seedance 2.0 生成视频时出现的常见问题(人物 ID 漂移/双胞胎/字幕/Logo/风格漂移/延长跳变/画质劣化/特效不对/中文发音/音色不准/结尾噪音 等 12 类),定位根因并给出修复后的提示词。用于"我的提示词生成出来不对"、"视频里出现奇怪的字幕"、"人脸不像参考图"、"出现两个一样的人物"、"0skills.sh installs