{"id":"347a8399-b259-43f4-8c83-69cb768b0ce9","shortId":"3JfGqu","kind":"skill","title":"123-java-exception-handling","tagline":"Use when you need to apply Java exception handling best practices — including using specific exception types, managing resources with try-with-resources, securing exception messages, preserving error context via exception chaining, validating inputs early with fail-fast principle","description":"# Java Exception Handling Guidelines\n\nIdentify and apply robust Java exception handling practices to improve error clarity, security, debuggability, and system reliability.\n\n**What is covered in this Skill?**\n\n- Specific exception types instead of generic `Exception`/`RuntimeException`\n- try-with-resources for automatic resource cleanup\n- Secure exception messages that avoid information leakage\n- Exception chaining to preserve full error context\n- Early input validation with `IllegalArgumentException`/`NullPointerException`\n- `InterruptedException` handling with interrupted-status restoration\n- `@throws` JavaDoc documentation, fail-fast principle\n- Structured logging with correlation IDs, avoiding log-and-throw duplication\n- API boundary translation via centralized exception mappers\n- Bounded retry with backoff for idempotent operations only\n- Timeout enforcement with deadline propagation\n- `Throwable#addSuppressed` for secondary cleanup failures\n- Never catching `Throwable`/`Error`\n- Observability via error metrics\n- Failure propagation in async `CompletionStage` code\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 exception handling changes, ensure the project compiles. If compilation fails, stop immediately — do not proceed until resolved. After applying improvements, run full verification.\n\n- **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any changes\n- **SAFETY**: If compilation fails, stop immediately — do not proceed until the project is in a valid state\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 exception handling pattern\n\n## When to use this skill\n\n- Exception handling\n- Use try-with-resources in Java code\n- Create exception chaining in Java code\n- Apply fail-fast validation in Java code\n\n## Workflow\n\n1. **Compile project before exception-handling changes**\n\nRun `./mvnw compile` or `mvn compile` and stop immediately if compilation fails.\n\n2. **Read exception-handling reference**\n\nRead `references/123-java-exception-handling.md` and identify applicable failure-handling and observability improvements.\n\n3. **Apply exception-handling improvements**\n\nRefactor to specific exceptions, safe resource handling, error translation, and consistent logging patterns.\n\n4. **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/123-java-exception-handling.md](references/123-java-exception-handling.md).","tags":["123","java","exception","handling","cursor","rules","jabrena","agent-skills","ai-skills","claude","claude-code","claude-code-skills"],"capabilities":["skill","source-jabrena","skill-123-java-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/123-java-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,781 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-26T18:53:40.876Z","embedding":null,"createdAt":"2026-04-18T22:01:56.369Z","updatedAt":"2026-04-26T18:53:40.876Z","lastSeenAt":"2026-04-26T18:53:40.876Z","tsv":"'/mvnw':223,251,317,370 '1':308 '123':1 '2':328 '3':345 '4':364 'addsuppress':155 'api':134 'appli':11,52,188,196,216,229,259,262,299,346,378 'applic':192,338 'area':187 'async':171 'automat':86 'avoid':93,128 'backoff':144 'base':190 'best':15 'bound':141 'boundari':135 'build':368 'catch':161 'central':138 'chain':37,97,295 'chang':200,231,315 'clariti':61 'clean':252,256,371,375 'cleanup':88,158 'code':173,182,292,298,306 'compil':204,206,224,227,234,309,318,321,326 'completionstag':172 'consist':361 'constraint':194,270,386 'context':34,102 'core':186 'correl':126 'cover':69 'creat':293 'deadlin':152 'debugg':63 'detail':267,382 'document':118 'duplic':133 'earli':40,103 'enforc':150 'ensur':201 'error':33,60,101,163,166,358 'exampl':180,193,269,384 'except':4,13,20,30,36,47,55,74,79,90,96,139,198,275,283,294,313,331,348,354 'exception-handl':312,330,347 'fail':43,120,207,235,301,327 'fail-fast':42,119,300 'failur':159,168,340 'failure-handl':339 'fast':44,121,302 'full':100,219,367 'generic':78 'good/bad':181,268 'guidanc':383 'guidelin':49 'handl':5,14,48,56,110,199,276,284,314,332,341,349,357 'id':127 'idempot':146 'identifi':50,337 'illegalargumentexcept':107 'immedi':209,237,324 'improv':59,217,260,344,350,379 'includ':17 'inform':94 'input':39,104 'instead':76 'interrupt':113 'interrupted-status':112 'interruptedexcept':109 'java':3,12,46,54,291,297,305 'java-exception-handl':2 'javadoc':117 'leakag':95 'log':124,130,362 'log-and-throw':129 'manag':22 'mandatori':221 'mapper':140 'messag':31,91 'metric':167 'mvn':226,255,320,374 'need':9 'never':160 'nullpointerexcept':108 'observ':164,343 'oper':147 'organ':178 'pattern':183,277,363 'practic':16,57 'preserv':32,99 'principl':45,122 'proceed':212,240 'project':203,243,310 'propag':153,169 'read':263,329,334 'recommend':189 'refactor':351 'refer':176,265,333,380 'references/123-java-exception-handling.md':335,388,389 'reliabl':66 'resolv':214 'resourc':23,28,84,87,289,356 'restor':115 'retri':142 'robust':53 'run':218,222,250,316,369 'runtimeexcept':80 'safe':355 'safeguard':272 'safeti':232 'scope':174 'secondari':157 'secur':29,62,89 'see':387 'skill':72,282 'skill-123-java-exception-handling' 'source-jabrena' 'specif':19,73,353 'state':248 'status':114 'stop':208,236,323 'structur':123 'system':65 'throw':116,132 'throwabl':154,162 'timeout':149 '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' 'translat':136,359 'tri':26,82,287 'try-with-resourc':25,81,286 'type':21,75 'use':6,18,280,285 'valid':38,105,247,303 'verif':220 'verifi':249,253,257,365,372,376 'via':35,137,165 'workflow':307","prices":[{"id":"afab584a-fd79-468a-94b1-8ead4dab7f11","listingId":"347a8399-b259-43f4-8c83-69cb768b0ce9","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:01:56.369Z"}],"sources":[{"listingId":"347a8399-b259-43f4-8c83-69cb768b0ce9","source":"github","sourceId":"jabrena/cursor-rules-java/123-java-exception-handling","sourceUrl":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/123-java-exception-handling","isPrimary":false,"firstSeenAt":"2026-04-18T22:01:56.369Z","lastSeenAt":"2026-04-26T18:53:40.876Z"}],"details":{"listingId":"347a8399-b259-43f4-8c83-69cb768b0ce9","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"jabrena","slug":"123-java-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-26T13:48:39Z","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":"3b4ba527fb6cef608a6a90560ccd354e8739f876","skill_md_path":"skills/123-java-exception-handling/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/123-java-exception-handling"},"layout":"multi","source":"github","category":"cursor-rules-java","frontmatter":{"name":"123-java-exception-handling","license":"Apache-2.0","description":"Use when you need to apply Java exception handling best practices — including using specific exception types, managing resources with try-with-resources, securing exception messages, preserving error context via exception chaining, validating inputs early with fail-fast principles, handling thread interruption correctly, documenting exceptions with @throws, enforcing logging policy, translating exceptions at API boundaries, managing retries and idempotency, enforcing timeouts, attaching suppressed exceptions, and propagating failures in async/reactive code. This should trigger for requests such as Exception handling; Use try-with-resources in Java code; Create exception chaining in Java code; Apply fail-fast validation in Java code. Part of cursor-rules-java project"},"skills_sh_url":"https://skills.sh/jabrena/cursor-rules-java/123-java-exception-handling"},"updatedAt":"2026-04-26T18:53:40.876Z"}}