
Error Handling Patterns
FreeMaster error handling for resilient applications.
Free · Opens the source repo
What Error Handling Patterns does
Error handling is a critical aspect of software development that can significantly impact application reliability and user experience. This skill provides a comprehensive guide to various error handling patterns applicable across multiple programming languages. It covers essential concepts such as exceptions, Result types, and error propagation strategies, enabling developers to build applications that can gracefully handle failures. By mastering these patterns, you can enhance debugging experiences and improve overall application resilience.
The skill outlines when to use different error handling philosophies, such as traditional exceptions for unexpected errors and Result types for expected failures. It also categorizes errors into recoverable and unrecoverable types, providing insights into how to manage each effectively. This structured approach helps developers make informed decisions about error handling in their applications, ensuring that they can respond appropriately to various failure scenarios.
In addition to theoretical knowledge, this skill includes practical best practices for implementing error handling. These practices emphasize the importance of meaningful error messages, preserving context for debugging, and cleaning up resources to prevent memory leaks. By following these guidelines, developers can create robust applications that not only handle errors effectively but also provide a better experience for users and developers alike.
Whether you are designing error-resilient APIs, debugging production issues, or implementing new features, this skill serves as a valuable resource. It equips you with the knowledge and strategies needed to tackle error handling challenges head-on, ultimately leading to more reliable and maintainable software solutions.
When to use it
Use this skill when developing new features, designing APIs, or debugging existing applications to ensure robust error handling.
When not to use it
This skill may not be suitable for projects that do not require advanced error handling or for very simple applications where basic error checking suffices.
What you can build with it
Designing APIs with Error Resilience
When creating an API, use this skill to implement error handling that anticipates common issues and provides clear feedback to users.
Debugging Production Issues
Utilize the patterns outlined in this skill to effectively diagnose and resolve errors encountered in a live application environment.
Implementing New Features
Incorporate robust error handling practices from this skill when adding new functionalities to ensure that your application remains stable and user-friendly.
How to install Error Handling Patterns
View source1. Install with the skills CLI
npx skills add wshobson/agents/error-handling-patterns --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by wshobsonError 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
- Fail Fast: Validate input early, fail quickly
- Preserve Context: Include stack traces, metadata, timestamps
- Meaningful Messages: Explain what happened and how to fix it
- Log Appropriately: Error = log, expected failure = don't spam logs
- Handle at Right Level: Catch where you can meaningfully handle
- Clean Up Resources: Use try-finally, context managers, defer
- Don't Swallow Errors: Log or re-throw, don't silently ignore
- 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 Exceptionhides 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
Frequently asked questions about Error Handling Patterns
Similar skills
Agent Host Debug Logs
Analyze Agent Host debug logs for deeper insights.
Code OSS Dev - Launch + Debug
Launch and debug Code OSS with isolated profiles.
Phoenix CLI
Debug LLM applications with structured analysis tools.
Power Automate Debugging
Diagnose and fix Power Automate flow errors effectively.
Arize Trace
Inspect and export traces for LLM applications.
Runtime Behavior Probe
Investigate real runtime behavior with precision.
