Master error handling patterns across languages including

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…
--- name: error-handling-patterns description: 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. --- # 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
Overview
Build resilient applications with robust error handling strategies that gracefully handle failures and provide excellent debugging experiences.
Manual install (npx, ZIP)
npx skills add wshobson/agents --skill error-handling-patterns -g -a claude-codemkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \
| tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/developer-essentials/skills/error-handling-patternsNew-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/08558dc9002e5dab71f2/error-handling-patterns.zip" -OutFile "$env:TEMP\error-handling-patterns.zip"; Expand-Archive "$env:TEMP\error-handling-patterns.zip" -DestinationPath "$HOME\.claude\skills" -ForceConnects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md4.0 KBreferences/1 file · 12.2 KB
Read the files here
Show the full text122 lines
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
- 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
| 1 | |
| 2 | name error-handling-patterns |
| 3 | description 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. |
| 4 | |
| 5 | |
| 6 | # Error Handling Patterns |
| 7 | |
| 8 | Build resilient applications with robust error handling strategies that gracefully handle failures and provide excellent debugging experiences. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | Implementing error handling in new features |
| 13 | Designing error-resilient APIs |
| 14 | Debugging production issues |
| 15 | Improving application reliability |
| 16 | Creating better error messages for users and developers |
| 17 | Implementing retry and circuit breaker patterns |
| 18 | Handling async/concurrent errors |
| 19 | Building fault-tolerant distributed systems |
| 20 | |
| 21 | ## Core Concepts |
| 22 | |
| 23 | ### 1. Error Handling Philosophies |
| 24 | |
| 25 | **Exceptions vs Result Types:** |
| 26 | |
| 27 | **Exceptions**: Traditional try-catch, disrupts control flow |
| 28 | **Result Types**: Explicit success/failure, functional approach |
| 29 | **Error Codes**: C-style, requires discipline |
| 30 | **Option/Maybe Types**: For nullable values |
| 31 | |
| 32 | **When to Use Each:** |
| 33 | |
| 34 | Exceptions: Unexpected errors, exceptional conditions |
| 35 | Result Types: Expected errors, validation failures |
| 36 | Panics/Crashes: Unrecoverable errors, programming bugs |
| 37 | |
| 38 | ### 2. Error Categories |
| 39 | |
| 40 | **Recoverable Errors:** |
| 41 | |
| 42 | Network timeouts |
| 43 | Missing files |
| 44 | Invalid user input |
| 45 | API rate limits |
| 46 | |
| 47 | **Unrecoverable Errors:** |
| 48 | |
| 49 | Out of memory |
| 50 | Stack overflow |
| 51 | Programming bugs (null pointer, etc.) |
| 52 | |
| 53 | ## Detailed patterns and worked examples |
| 54 | |
| 55 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 56 | |
| 57 | ## Best Practices |
| 58 | |
| 59 | **Fail Fast**: Validate input early, fail quickly |
| 60 | **Preserve Context**: Include stack traces, metadata, timestamps |
| 61 | **Meaningful Messages**: Explain what happened and how to fix it |
| 62 | **Log Appropriately**: Error = log, expected failure = don't spam logs |
| 63 | **Handle at Right Level**: Catch where you can meaningfully handle |
| 64 | **Clean Up Resources**: Use try-finally, context managers, defer |
| 65 | **Don't Swallow Errors**: Log or re-throw, don't silently ignore |
| 66 | **Type-Safe Errors**: Use typed errors when possible |
| 67 | |
| 68 | |
| 69 | # Good error handling example |
| 70 | def process_order(order_id: str) -> Order: |
| 71 | """Process order with comprehensive error handling.""" |
| 72 | try: |
| 73 | # Validate input |
| 74 | if not order_id: |
| 75 | raise ValidationError("Order ID is required") |
| 76 | |
| 77 | # Fetch order |
| 78 | order = db.get_order(order_id) |
| 79 | if not order: |
| 80 | raise NotFoundError("Order", order_id) |
| 81 | |
| 82 | # Process payment |
| 83 | try: |
| 84 | payment_result = payment_service.charge(order.total) |
| 85 | except PaymentServiceError as e: |
| 86 | # Log and wrap external service error |
| 87 | logger.error(f"Payment failed for order {order_id}: {e}") |
| 88 | raise ExternalServiceError( |
| 89 | f"Payment processing failed", |
| 90 | service="payment_service", |
| 91 | details={"order_id": order_id, "amount": order.total} |
| 92 | ) from e |
| 93 | |
| 94 | # Update order |
| 95 | order.status = "completed" |
| 96 | order.payment_id = payment_result.id |
| 97 | db.save(order) |
| 98 | |
| 99 | return order |
| 100 | |
| 101 | except ApplicationError: |
| 102 | # Re-raise known application errors |
| 103 | raise |
| 104 | except Exception as e: |
| 105 | # Log unexpected errors |
| 106 | logger.exception(f"Unexpected error processing order {order_id}") |
| 107 | raise ApplicationError( |
| 108 | "Order processing failed", |
| 109 | code="INTERNAL_ERROR" |
| 110 | ) from e |
| 111 | |
| 112 | |
| 113 | ## Common Pitfalls |
| 114 | |
| 115 | **Catching Too Broadly**: `except Exception` hides bugs |
| 116 | **Empty Catch Blocks**: Silently swallowing errors |
| 117 | **Logging and Re-throwing**: Creates duplicate log entries |
| 118 | **Not Cleaning Up**: Forgetting to close files, connections |
| 119 | **Poor Error Messages**: "Error occurred" is not helpful |
| 120 | **Returning Error Codes**: Use exceptions or Result types |
| 121 | **Ignoring Async Errors**: Unhandled promise rejections |
| 122 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
MCPExpert debugging specialist for errors, test failuresDebugger Agent
SkillEncountering any bug, test failure, or unexpected behaviorSystematic debugging
SkillRequires running verification commands and confirming outputVerification before completion
SkillGuides systematic root-cause debuggingDebugging and error recovery
SkillMaster systematic debugging techniques, profiling toolsDebugging strategies
SkillCreate structured incident response runbooksIncident runbook templatesMore from wshobson
SkillMaster C/.NET backend development patterns for building
SkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliance
SkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Design
SkillMigrate from AngularJS to Angular using hybrid modeAngular migration
SkillUnderstand anti-reversing, obfuscationAnti reversing techniques
SkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patterns