Skip to content

Error Handling Patterns

Verified

Implement comprehensive error handling with typed errors, recovery strategies, logging integration, and user-friendly messages.

By agent-skills 5,920 v1.6.0 Updated 2026-03-10

Install

Claude Code

claude install error-handling

About This Skill

Overview

Error Handling Patterns transforms ad-hoc try/catch blocks into systematic, comprehensive error management. It implements typed error hierarchies, recovery strategies, and proper logging that make your application resilient and debuggable.

Key Features

  • Typed Error Hierarchies: Creates custom error classes organized by domain (ValidationError, AuthenticationError, NotFoundError) with proper inheritance, error codes, and metadata fields.
  • Result Pattern: Implements Result/Either types for languages that support them, making error paths explicit in function signatures rather than relying on thrown exceptions.
  • Recovery Strategies: Adds retry logic with exponential backoff and jitter for network calls, circuit breaker patterns for failing dependencies, and graceful degradation for non-critical features.
  • Structured Logging: Integrates with popular logging libraries (Pino, Winston, structlog) to produce JSON-formatted logs with error context, stack traces, and correlation IDs for request tracing.

Error Boundaries

For frontend applications, generates React Error Boundaries with fallback UIs, error reporting to monitoring services, and recovery mechanisms. Server-side generates global error handlers with proper HTTP status code mapping.

Best Practices

Errors are categorized as operational (expected, recoverable) or programmer errors (bugs). Each category has appropriate handling: operational errors get recovery logic, programmer errors get logged and reported for fixing.

Use Cases

  • Create typed error hierarchies for different failure categories
  • Implement Result/Either patterns for explicit error propagation
  • Add retry logic with exponential backoff for transient failures
  • Set up structured error logging with correlation IDs for distributed systems
  • Generate user-friendly error messages from internal error types

Pros & Cons

Pros

  • + Typed errors make error handling explicit and compiler-checkable
  • + Recovery strategies (retry, circuit breaker) prevent cascading failures
  • + Structured logging with correlation IDs simplifies production debugging
  • + Clear separation of user-facing messages from internal error details

Cons

  • - Adding comprehensive error handling increases code volume significantly
  • - Result pattern adoption requires team-wide buy-in for consistency
  • - Over-engineering error handling for simple scripts can be counterproductive

Related AI Tools

Related Skills

Stay Updated on Agent Skills

Get weekly curated skills + safety alerts

每周精选 Skills + 安全预警