Error Handling Patterns skill for Claude

Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications.

When Claude uses it

Use when implementing error handling, designing APIs, or improving application reliability.

Error Handling Patterns SKILL.md

The full skill file from wshobson/agents (MIT).

Error Handling Patterns

Build resilient applications with robust error handling strategies that gracefully handle failures and provide excellent debugging experiences.

When to Use This Skill

  • Implementing error handling in new features
  • Designing error-resilient APIs
  • Debugging production issues
  • Improving application reliability
  • Creating better error messages for users and developers
  • Implementing retry and circuit breaker patterns
  • Handling async/concurrent errors
  • Building fault-tolerant distributed systems

Core Concepts

1. Error Handling Philosophies

Exceptions vs Result Types:

  • Exceptions: Traditional try-catch, disrupts control flow
  • Result Types: Explicit success/failure, functional approach
  • Error Codes: C-style, requires discipline
  • Option/Maybe Types: For nullable values

When to Use Each:

  • Exceptions: Unexpected errors, exceptional conditions
  • Result Types: Expected errors, validation failures
  • Panics/Crashes: Unrecoverable errors, programming bugs

2. Error Categories

Recoverable Errors:

  • Network timeouts
  • Missing files
  • Invalid user input
  • API rate limits

Unrecoverable Errors:

  • Out of memory
  • Stack overflow
  • Programming bugs (null pointer, etc.)

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

  1. Fail Fast: Validate input early, fail quickly
  2. Preserve Context: Include stack traces, metadata, timestamps
  3. Meaningful Messages: Explain what happened and how to fix it
  4. Log Appropriately: Error = log, expected failure = don't spam logs
  5. Handle at Right Level: Catch where you can meaningfully handle
  6. Clean Up Resources: Use try-finally, context managers, defer
  7. Don't Swallow Errors: Log or re-throw, don't silently ignore
  8. Type-Safe Errors: Use typed errors when possible
# Good error handling example
def process_order(order_id: str) -> Order:
    """Process order with comprehensive error handling."""
    try:
        # Validate input
        if not order_id:
            raise ValidationError("Order ID is required")

        # Fetch order
        order = db.get_order(order_id)
        if not order:
            raise NotFoundError("Order", order_id)

        # Process payment
        try:
            payment_result = payment_service.charge(order.total)
        except PaymentServiceError as e:
            # Log and wrap external service error
            logger.error(f"Payment failed for order {order_id}: {e}")
            raise ExternalServiceError(
                f"Payment processing failed",
                service="payment_service",
                details={"order_id": order_id, "amount": order.total}
            ) from e

        # Update order
        order.status = "completed"
        order.payment_id = payment_result.id
        db.save(order)

        return order

    except ApplicationError:
        # Re-raise known application errors
        raise
    except Exception as e:
        # Log unexpected errors
        logger.exception(f"Unexpected error processing order {order_id}")
        raise ApplicationError(
            "Order processing failed",
            code="INTERNAL_ERROR"
        ) from e

Common Pitfalls

  • Catching Too Broadly: except Exception hides bugs
  • Empty Catch Blocks: Silently swallowing errors
  • Logging and Re-throwing: Creates duplicate log entries
  • Not Cleaning Up: Forgetting to close files, connections
  • Poor Error Messages: "Error occurred" is not helpful
  • Returning Error Codes: Use exceptions or Result types
  • Ignoring Async Errors: Unhandled promise rejections

How to install Error Handling Patterns

Claude Code

Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):

npx degit wshobson/agents/plugins/developer-essentials/skills/error-handling-patterns#main ~/.claude/skills/error-handling-patterns

Codex

npx degit wshobson/agents/plugins/developer-essentials/skills/error-handling-patterns#main ~/.codex/skills/error-handling-patterns

Claude.ai and Claude Desktop

Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.

Frequently asked questions

+What does the Error Handling Patterns skill do?

Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.

+How do I install Error Handling Patterns in Claude Code?

Copy the skill folder into ~/.claude/skills/error-handling-patterns, for example with "npx degit wshobson/agents/plugins/developer-essentials/skills/error-handling-patterns#main ~/.claude/skills/error-handling-patterns". Claude Code loads it automatically and uses it when a task matches.

+Does Error Handling Patterns work with ChatGPT or Codex?

Yes. Error Handling Patterns uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/error-handling-patterns. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.

+Is Error Handling Patterns free?

Error Handling Patterns is published on GitHub by wshobson under the MIT license, which allows free use.

Related design & frontend skills

  1. Design

    Comprehensive design skill: brand identity, design tokens, UI styling, logo generation (55 styles, Gemini, Atlas Cloud, MuAPI, or UberLLM…

    nextlevelbuilder/ui-ux-pro-max-skill★ 151k
  2. Frontend Design

    Official

    Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one.

    anthropics/skills★ 197k
  3. Ui Ux Pro Max

    UI/UX design intelligence for web, mobile, and desktop. This skill should be used when designing, building, reviewing, or fixing…

    nextlevelbuilder/ui-ux-pro-max-skill★ 151k
  4. Event Store Design

    Design and implement event stores for event-sourced systems. Use when building event sourcing infrastructure, choosing event store…

    wshobson/agents★ 43k
  5. Interaction Design

    Design and implement microinteractions, motion design, transitions, and user feedback patterns.

    wshobson/agents★ 43k
  6. Mobile Android Design

    Master Material Design 3 and Jetpack Compose patterns for building native Android apps.

    wshobson/agents★ 43k
  7. Parallel Feature Development

    Coordinate parallel feature development with file ownership strategies, conflict avoidance rules, and integration patterns for multi-agent…

    wshobson/agents★ 43k
  8. Postgresql Table Design

    Use this skill when designing or reviewing a PostgreSQL-specific schema.

    wshobson/agents★ 43k
  9. React Modernization

    Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features.

    wshobson/agents★ 43k

See all design & frontend skills →

More skills from wshobson

  1. Eval Harness First

    Build the evaluation harness that gates every fine-tuning run — golden sets, per-failure-mode graders, judge calibration, and base-model…

    wshobson/agents★ 43k
  2. Evaluation Methodology

    PluginEval quality methodology, covering dimensions, rubrics, and scoring formulas.

    wshobson/agents★ 43k

All skills by wshobson →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.