143-java-functional-exception-handling
推动更可组合、可预测的错误处理策略
用 Optional、Either 与单子化管道替代异常滥用,改善错误处理
用 Optional、VAVR 的 Either 等“单子”替代异常滥用,把成功/失败当成值来传递,避免到处抛 NullPointerException。适合重构 Java 代码时清晰化错误边界、提升可测试性和性能,把 exceptions 留给真正的系统级不可恢复错误。还会建议用 sealed classes 和 enum 设计错误类型层次,并用 monadic 管道组合错误处理逻辑。
▸ 展开 SKILL.md 英文原文
Use when you need to apply functional exception handling best practices in Java — including replacing exception overuse with Optional and VAVR Either types, designing error type hierarchies using sealed classes and enums, implementing monadic error composition pipelines, establishing functional control flow patterns, and reserving exceptions only for truly exceptional system-level failures. This should trigger for requests such as Improve the code with Functional Exception Handling; Apply Functional Exception Handling; Refactor the code with Functional Exception Handling. Part of cursor-rules-java project
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/143-java-functional-exception-handling/SKILL.mdcurl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/143-java-functional-exception-handling/SKILL.md"# 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` f