143-java-functional-exception-handling

仓库创建 2025年2月9日最近提交 3 天前SkillHot 收录 21 天前
▸ 精选理由

推动更可组合、可预测的错误处理策略

这个 Skill 做什么

用 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

开发编程Java异常处理函数式通用
423
Stars
89
Forks
40
仓库内 Skill
+9
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/143-java-functional-exception-handling/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/143-java-functional-exception-handling/SKILL.md"
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
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有