{"id":"40758d74-c3c3-415e-8592-5371f9073a02","shortId":"WDAuB3","kind":"skill","title":"143-java-functional-exception-handling","tagline":"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, establis","description":"# Java Functional Exception handling Best Practices\n\nIdentify 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.\n\n**What is covered in this Skill?**\n\n- `Optional<T>` for nullable values over throwing `NullPointerException` or `NotFoundException`\n- VAVR `Either<L,R>` for predictable business-logic failures\n- `CompletableFuture<T>` for async error handling\n- Sealed classes and records for rich error type hierarchies with exhaustive pattern matching\n- Enum-based error types for simple failure cases\n- Functional composition: `flatMap`/`map`/`peek`/`peekLeft` for chaining operations that can fail\n- Structured logging: warn/info for business failures, error for system failures\n- Checked vs unchecked exception discipline\n- Exception chaining with full causal context when exceptions are unavoidable\n\n**Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.\n\n## Constraints\n\nBefore applying any functional exception handling changes, ensure the project validates. When introducing Either types, confirm the VAVR dependency (io.vavr:vavr) and SLF4J are present.\n\n- **MANDATORY**: Run `./mvnw validate` or `mvn validate` before applying any changes\n- **SAFETY**: If validation fails, stop immediately — do not proceed until the project is in a valid state\n- **DEPENDENCY**: When introducing `Either` types, confirm VAVR (`io.vavr:vavr`) and SLF4J are present\n- **VERIFY**: Run `./mvnw clean verify` or `mvn clean verify` after applying improvements\n- **BEFORE APPLYING**: Read the reference for detailed good/bad examples, constraints, and safeguards for each functional exception handling pattern\n\n## When to use this skill\n\n- Improve the code with Functional Exception Handling\n- Apply Functional Exception Handling\n- Refactor the code with Functional Exception Handling\n\n## Workflow\n\n1. **Validate project before functional-exception changes**\n\nRun `./mvnw validate` or `mvn validate` and stop immediately if validation fails.\n\n2. **Check required dependencies**\n\nWhen introducing `Either`, confirm VAVR (`io.vavr:vavr`) and SLF4J are present before implementation.\n\n3. **Read functional-exception reference and identify targets**\n\nRead `references/143-java-functional-exception-handling.md` and identify places to replace exception-heavy control flow with monadic error types.\n\n4. **Apply functional exception-handling refactorings**\n\nImplement selected `Optional`/`Either`/async error patterns with structured logging and clear error contracts.\n\n5. **Verify with full build**\n\nRun `./mvnw clean verify` or `mvn clean verify` after applying improvements.\n\n## Reference\n\nFor detailed guidance, examples, and constraints, see [references/143-java-functional-exception-handling.md](references/143-java-functional-exception-handling.md).","tags":["143","java","functional","exception","handling","cursor","rules","jabrena","agent-skills","ai-skills","claude","claude-code"],"capabilities":["skill","source-jabrena","skill-143-java-functional-exception-handling","topic-agent-skills","topic-ai-skills","topic-claude","topic-claude-code","topic-claude-code-skills","topic-claude-code-subagents","topic-claude-skills","topic-cursor-agent","topic-cursor-ai","topic-cursor-skills","topic-cursorai","topic-github-copilot"],"categories":["cursor-rules-java"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/jabrena/cursor-rules-java/143-java-functional-exception-handling","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add jabrena/cursor-rules-java","source_repo":"https://github.com/jabrena/cursor-rules-java","install_from":"skills.sh"}},"qualityScore":"0.631","qualityRationale":"deterministic score 0.63 from registry signals: · indexed on github topic:agent-skills · 362 github stars · SKILL.md body (2,965 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-26T12:53:35.603Z","embedding":null,"createdAt":"2026-04-18T22:02:04.113Z","updatedAt":"2026-04-26T12:53:35.603Z","lastSeenAt":"2026-04-26T12:53:35.603Z","tsv":"'/async':381 '/mvnw':215,256,317,397 '1':308 '143':1 '2':328 '3':345 '4':370 '5':391 'appli':12,53,181,189,221,264,267,296,371,405 'applic':185 'area':180 'async':105 'base':123,183 'best':16,49,57 'build':395 'busi':100,146 'business-log':99 'case':129 'causal':161 'chain':137,158 'chang':194,223,315 'check':152,329 'clariti':64 'class':36,109 'clean':257,261,398,402 'clear':388 'code':175,291,302 'completablefutur':103 'composit':42,131 'confirm':203,246,335 'constraint':187,275,413 'context':162 'contract':390 'control':364 'core':179 'cover':80 'depend':206,241,331 'design':30 'detail':272,409 'disciplin':156 'either':28,94,201,244,334,380 'elimin':69 'ensur':195 'enum':38,122 'enum-bas':121 'error':31,41,63,76,106,114,124,148,368,382,389 'establ':44 'exampl':173,186,274,411 'except':5,14,22,47,55,70,155,157,164,192,281,294,298,305,314,349,362,374 'exception-handl':373 'exception-heavi':361 'exhaust':118 'fail':141,227,327 'failur':102,128,147,151 'favour':73 'flatmap':132 'flow':365 'full':160,394 'function':4,13,46,54,130,191,280,293,297,304,313,348,372 'functional-except':312,347 'good/bad':174,273 'guidanc':410 'handl':6,15,48,56,107,193,282,295,299,306,375 'heavi':363 'hierarchi':33,116 'identifi':51,352,357 'immedi':229,324 'implement':39,344,377 'improv':62,265,289,406 'includ':20 'introduc':200,243,333 'io.vavr':207,248,337 'java':3,19,45,60 'java-functional-exception-handl':2 'l':95 'log':143,386 'logic':101 'maintain':65 'mandatori':213 'map':133 'match':120 'monad':40,75,367 'mvn':218,260,320,401 'need':10 'notfoundexcept':92 'nullabl':86 'nullpointerexcept':90 'oper':138 'option':25,84,379 'organ':171 'overus':23,71 'pattern':119,176,283,383 'peek':134 'peekleft':135 'perform':67 'pipelin':43 'place':358 'practic':17,50,58 'predict':98 'present':212,253,342 'proceed':232 'project':197,235,310 'r':96 'read':268,346,354 'recommend':182 'record':111 'refactor':300,376 'refer':169,270,350,407 'references/143-java-functional-exception-handling.md':355,415,416 'replac':21,360 'requir':330 'rich':113 'run':214,255,316,396 'safeguard':277 'safeti':224 'scope':167 'seal':35,108 'see':414 'select':378 'simpl':127 'skill':83,288 'skill-143-java-functional-exception-handling' 'slf4j':210,251,340 'source-jabrena' 'state':240 'stop':228,323 'structur':142,385 'system':150 'target':353 'throw':89 'topic-agent-skills' 'topic-ai-skills' 'topic-claude' 'topic-claude-code' 'topic-claude-code-skills' 'topic-claude-code-subagents' 'topic-claude-skills' 'topic-cursor-agent' 'topic-cursor-ai' 'topic-cursor-skills' 'topic-cursorai' 'topic-github-copilot' 'type':29,32,77,115,125,202,245,369 'unavoid':166 'uncheck':154 'use':7,34,286 'valid':198,216,219,226,239,309,318,321,326 'valu':87 'vavr':27,93,205,208,247,249,336,338 'verifi':254,258,262,392,399,403 'vs':153 'warn/info':144 'workflow':307","prices":[{"id":"0af1309f-16be-49be-9469-0bd1b67c27b4","listingId":"40758d74-c3c3-415e-8592-5371f9073a02","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"jabrena","category":"cursor-rules-java","install_from":"skills.sh"},"createdAt":"2026-04-18T22:02:04.113Z"}],"sources":[{"listingId":"40758d74-c3c3-415e-8592-5371f9073a02","source":"github","sourceId":"jabrena/cursor-rules-java/143-java-functional-exception-handling","sourceUrl":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/143-java-functional-exception-handling","isPrimary":false,"firstSeenAt":"2026-04-18T22:02:04.113Z","lastSeenAt":"2026-04-26T12:53:35.603Z"}],"details":{"listingId":"40758d74-c3c3-415e-8592-5371f9073a02","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"jabrena","slug":"143-java-functional-exception-handling","github":{"repo":"jabrena/cursor-rules-java","stars":362,"topics":["agent-skills","ai-skills","claude","claude-code","claude-code-skills","claude-code-subagents","claude-skills","cursor-agent","cursor-ai","cursor-skills","cursorai","github-copilot","intellij-idea","java","prompting","system-prompts"],"license":"apache-2.0","html_url":"https://github.com/jabrena/cursor-rules-java","pushed_at":"2026-04-26T12:50:01Z","description":"A curated and opinionated collection of Skills and Agents to be used in modern SDLC workflows for Java Enterprise development with your favorite AI Agent harness.","skill_md_sha":"5f595232b33ec384e4b96e39ea9a765aef60e227","skill_md_path":"skills/143-java-functional-exception-handling/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/143-java-functional-exception-handling"},"layout":"multi","source":"github","category":"cursor-rules-java","frontmatter":{"name":"143-java-functional-exception-handling","license":"Apache-2.0","description":"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"},"skills_sh_url":"https://skills.sh/jabrena/cursor-rules-java/143-java-functional-exception-handling"},"updatedAt":"2026-04-26T12:53:35.603Z"}}