# error-handling-patterns > 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. - Author: cksaraswatalgomatic-eng - Repository: cksaraswatalgomatic-eng/opushire - Version: 20260124142127 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/cksaraswatalgomatic-eng/opushire - Web: https://mule.run/skillshub/@@cksaraswatalgomatic-eng/opushire~error-handling-patterns:20260124142127 --- --- 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 - Building fault-tolerant distributed systems ## Core Concepts ### 1. Error Handling Philosophies **Exceptions vs Result Types:** - **Exceptions:** Traditional try-catch, disrupts control flow. Use for unexpected errors, exceptional conditions. - **Result Types:** Explicit success/failure, functional approach. Use for expected errors, validation failures. - **Error Codes:** C-style, requires discipline. - **Option/Maybe Types:** For nullable values. **Panics/Crashes:** Use for 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.). ## Language-Specific Patterns Consult the specific resource files for detailed implementation patterns in your language: - **Python:** [`resources/python-patterns.md`](resources/python-patterns.md) (Custom exceptions, Context managers, Retries) - **TypeScript/JavaScript:** [`resources/typescript-patterns.md`](resources/typescript-patterns.md) (Custom Error classes, Result types, Async handling) - **Rust:** [`resources/rust-patterns.md`](resources/rust-patterns.md) (Result/Option types, Custom enums) - **Go:** [`resources/go-patterns.md`](resources/go-patterns.md) (Explicit error returns, Sentinel errors) ## Universal Patterns For cross-language architectural patterns like Circuit Breakers, Error Aggregation, and Graceful Degradation, see: 👉 **[`resources/universal-patterns.md`](resources/universal-patterns.md)** ## 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. ## 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. ## Resources - `references/exception-hierarchy-design.md`: Designing error class hierarchies - `references/error-recovery-strategies.md`: Recovery patterns for different scenarios - `references/async-error-handling.md`: Handling errors in concurrent code - `assets/error-handling-checklist.md`: Review checklist for error handling - `assets/error-message-guide.md`: Writing helpful error messages - `scripts/error-analyzer.py`: Analyze error patterns in logs