Skip to main content
skill CX Codex

126-java-exception-handling — Claude Code skill: install guide

126-java-exception-handling is a Claude Code skill for Java exception handling. It activates on requests to review error types, resource cleanup, or failure propagation.

Apache-2.0 307 installs ★ 465 updated 2026-10-21

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add jabrena/plinth --skill 126-java-exception-handling -a claude-code
Open on GitHub

What 126-java-exception-handling does

The skill guides changes to Java error handling, including choosing specific exception classes, closing resources with try-with-resources, and retaining context when wrapping an error. It also covers safe exception messages, thread interruption, logging, timeouts, retries for idempotent operations, and failures in asynchronous code.

Before editing, the agent runs ./mvnw compile or mvn compile and stops if compilation fails. It then reads references/126-java-exception-handling.md, applies relevant guidance, and runs ./mvnw clean verify or mvn clean verify to check the result.

What it helps with

  • replace overly broad exception types with specific ones
  • close resources using try-with-resources
  • retain the cause when translating an exception
  • review interruption handling and async failure propagation

Example prompts for the agent

  • Review the Java exception handling and suggest suitable changes.
  • Refactor this code to use try-with-resources.
  • Preserve the original error context when wrapping this exception.

How to install 126-java-exception-handling

1Skills CLI (Vercel)

npx skills add jabrena/plinth --skill 126-java-exception-handling -a claude-code

2Manually: put the files in place

~/.claude/skills/126-java-exception-handling/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/126-java-exception-handling/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about 126-java-exception-handling

How do I install 126-java-exception-handling in Claude Code?

Run npx skills add jabrena/plinth --skill 126-java-exception-handling -a claude-code. The skill file is placed at ~/.claude/skills/126-java-exception-handling/SKILL.md.

What does 126-java-exception-handling do?

It guides Java exception-handling changes, from selecting exception classes and cleaning up resources to logging and passing failures across API boundaries.

What does 126-java-exception-handling need to run?

The project must compile before edits; the skill runs ./mvnw compile or mvn compile. After changes, it checks the build with ./mvnw clean verify or mvn clean verify.

Source text

SKILL.md · Apache-2.0
---
name: 126-java-exception-handling
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; Review Java exception taxonomy and propagation. Part of Plinth Toolkit
license: Apache-2.0
metadata:
  author: Juan Antonio Breña Moral
  version: 0.19.0
---
# Java Exception Handling Guidelines

Identify and apply robust Java exception handling practices to improve error clarity, security, debuggability, and system reliability.

**What is covered in this Skill?**

- Specific exception types instead of generic `Exception`/`RuntimeException`
- try-with-resources for automatic resource cleanup
- Secure exception messages that avoid information leakage
- Exception chaining to preserve full error context
- Early input validation with `IllegalArgumentException`/`NullPointerException`
- `InterruptedException` handling with interrupted-status restoration
- `@throws` JavaDoc documentation, fail-fast principle
- Structured logging with correlation IDs, avoiding log-and-throw duplication
- API boundary translation via centralized exception mappers
- Bounded retry with backoff for idempotent operations only
- Timeout enforcement with deadline propagation
- `Throwable#addSuppressed` for secondary cleanup failures
- Never catching `Throwable`/`Error`
- Observability via error metrics
- Failure propagation in async `CompletionStage` code

**Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.

## Constraints

Before 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.

- **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any changes
- **SAFETY**: If compilation fails, stop immediately — do not proceed until the project is in a valid state
- **VERIFY**: Run `./mvnw clean verify` or `mvn clean verify` after applying improvements
- **BEFORE APPLYING**: Read the reference for detailed good/bad examples, constraints, and safeguards for each exception handling pattern

## When to use this skill

- Exception handling
- Use try-with-resources in Java code
- Create exception chaining in Java code
- Apply fail-fast validation in Java code
- Review Java exception taxonomy and propagation

## Workflow

1. **Compile project before exception-handling changes**

Run `./mvnw compile` or `mvn compile` and stop immediately if compilation fails.

2. **Read exception-handling reference**

Read `references/126-java-exception-handling.md` and identify applicable failure-handling and observability improvements.

3. **Apply exception-handling improvements**

Refactor to specific exceptions, safe resource handling, error translation, and consistent logging patterns.

4. **Verify with full build**

Run `./mvnw clean verify` or `mvn clean verify` after applying improvements.

## Reference

For detailed guidance, examples, and constraints, see [references/126-java-exception-handling.md](references/126-java-exception-handling.md).

© Juan Antonio Breña Moral · Apache-2.0 · jabrena/plinth

Similar skills

All skills for Programming languages →

From the same set123

The whole set →
511-frameworks-micronaut-jdbc 511-frameworks-micronaut-jdbc — a skill for reviewing Micronaut JDBC code, covering SQL binding, transactions, pooled connections, batching, and database error mapping. CX Codex +1 318installs 513-frameworks-micronaut-db-migrations-flyway The 513-frameworks-micronaut-db-migrations-flyway skill guides Flyway migration work in Micronaut, covering SQL files, datasource settings, migration order, tests, and schema-change safety. CX Codex +1 317installs 002-agents-inventory 002-agents-inventory — a skill to auto-generate a checklist with an embedded Java agent inventory. Produces INVENTORY-AGENTS-JAVA.md by strictly following a template, preserving exact structure and content. CX Codex +1 314installs 043-planning-github-issues 043-planning-github-issues guides GitHub CLI setup and keeps issue prose outside agent context, relying on repository-owned documents for requirements analysis. CX Codex +1 312installs 703-technologies-fuzzing-testing The 703-technologies-fuzzing-testing skill guides CATS-based fuzz testing for Java APIs from an OpenAPI contract. Use it to probe invalid inputs, boundary conditions, and CI checks. CX Codex +1 304installs 314-frameworks-spring-kafka 314-frameworks-spring-kafka guides Kafka messaging setup in Spring Boot projects, covering consumers, DLT retries, and Testcontainers. CX Codex +1 297installs 182-java-observability-metrics-micrometer 182-java-observability-metrics-micrometer guides Java developers through Micrometer metrics design and validation. Use it when adding service measurements or revising existing instrumentation. CX Codex +1 297installs 403-frameworks-quarkus-validation 403-frameworks-quarkus-validation guides Quarkus validation work, from DTO constraints and REST boundaries to configuration checks and API error mapping. CX Codex +1 296installs

Project sponsors

Companies that keep this analytics open