---
title: Error Handling Patterns
category: product
entity_type: skill
price: $15
canonical: https://forgehouse.ai/skills/error-handling-patterns/
lang: en
hreflang_alt: https://forgehouse.ai/tr/skiller/error-handling-patterns/
last_updated: 2026-06-20
---

# Error Handling Patterns

> Master error handling patterns across languages including exceptions, Result types, error…

A cross-language playbook for building resilient applications that fail safely instead of crashing silently. It covers exception hierarchies, Result/Option types, retry with backoff, circuit breakers and graceful degradation across Python, TypeScript, Rust and Go, turning ad-hoc try-catch blocks into a deliberate reliability strategy.

## Use cases
- Designing a typed error hierarchy (Validation, NotFound, ExternalService) with HTTP status mapping
- Adding retry with exponential backoff for flaky network and external-API calls
- Wrapping a payment or email integration in a circuit breaker to stop cascading failures
- Returning explicit Result types instead of throwing for expected validation failures
- Aggregating multiple validation errors instead of failing on the first one
- Building graceful fallbacks (cache then database, primary then secondary provider)

## Benefits
- Replace silent failures with actionable user messages and proper monitoring alerts
- Contain the blast radius of any single fault so one integration outage doesn't take down everything
- Spend less time debugging production by preserving context, timestamps and structured logs
- Distinguish transient errors (retry) from permanent ones (fail fast) to avoid wasting resources

## What’s included
- Custom exception hierarchy examples in Python and TypeScript with error codes and details
- Result/Option type pattern with Ok/Err helpers and chaining for explicit error flow
- Full circuit breaker implementation (closed/open/half-open) with failure thresholds and timeout
- Retry decorator with configurable backoff factor and exception filtering
- Error aggregation collector and multi-fallback graceful degradation helpers
- Rust ? operator and From conversions, Go sentinel errors with errors.Is/errors.As patterns

## Who it’s for
Backend and full-stack engineers building APIs and distributed systems who want fault tolerance that is designed in, not bolted on after an outage.

## How it runs
The skill treats every failure as a designed path, not an accident. The loop it runs when wiring error handling into a system:
1. Categorizes each possible failure by blast radius first: ValidationError touches one request, DatabaseError touches all writes, ExternalServiceError touches one integration. Each category gets its own recovery strategy before any code is written.
2. Builds a typed error hierarchy (AppError base, then ValidationError 400, AuthError 401, NotFoundError 404, ConflictError 409, InternalError 500), each carrying an error code, HTTP status and a user-facing message.
3. Applies fail-fast at the boundary: input validation at the very top of the handler so invalid data never reaches business logic. Expected failures return Result types; exceptions are reserved for the truly unexpected.
4. Routes transient failures (network timeout, 503) to retry with exponential backoff, and chronic failures to a circuit breaker: 5 consecutive fails opens the circuit for 60 seconds, a half-open probe tests recovery, fallback responses serve meanwhile.
5. Designs graceful degradation per dependency: payment down means queue the order and tell the user it is processing, search timeout means serve cached results, image service down means placeholder. Silent quality drops are forbidden.
6. Logs every error structured (timestamp, request ID, user ID, error code, stack, context) and never swallows one: empty catch blocks are the cardinal sin. Error budget tracking (99.9% SLO equals 43 minutes per month) decides when feature work stops for stability work.

## FAQ
### My stack is only TypeScript, is the cross-language coverage wasted on me?
No, each pattern is shown per language, so you use the TypeScript implementations directly and ignore the rest. The cross-language framing only matters if you run a polyglot backend.

### Won't retries and circuit breakers just add complexity I don't actually need?
Each pattern targets a specific failure mode, so you add a circuit breaker around a flaky payment call, not around everything. Applied where the failure actually happens, they remove cascading outages rather than adding noise.

### Does this replace a resilience library or my monitoring?
No, it is design patterns and typed-error structure, not a packaged library or an observability tool. It tells you what to build and where, you still wire in your own libraries and monitoring.

## Price
$15, one-time, no subscription. VAT included.

Related guide: [AI code review and developer workflow](https://forgehouse.ai/guides/ai-code-review/)
