Error Handling Strategies

Author: Htunn Thu Thu

Date: January 4, 2026

Tags: #SoftwareDesign #TypeScript #ErrorHandling #Reliability

Introduction

Good error handling is the difference between an application that crashes mysteriously and one that fails gracefully. Building distributed systems like my IoT monitoring platform taught me that errors aren't exceptionalβ€”they're normal, and we need to design for them.

This guide covers:

  • Error Types - Understanding different error categories

  • Error Handling Patterns - Try-catch, Result types, error boundaries

  • Defensive Programming - Validation and safeguards

  • Fault Tolerance - Retries, fallbacks, circuit breakers

  • Error Reporting - Logging and monitoring


Understanding Error Types

Operational vs. Programming Errors

// Operational errors: Expected runtime issues
// - Network failures
// - Database connection lost
// - Invalid user input
// - File not found
// - API rate limits exceeded

// Programming errors: Bugs in code
// - TypeError: Cannot read property of undefined
// - ReferenceError: Variable not declared
// - Logic errors
// - Incorrect assumptions

Real Example from My Projects


Error Handling Patterns

Traditional Try-Catch

Result Type Pattern

Instead of throwing, return success or failure:

Real Example: My IoT Platform Error Handling


Defensive Programming

Input Validation

Null Safety

Real Example: Defensive Database Operations


Fault Tolerance

Retry Logic

Circuit Breaker Pattern

Fallback Strategies


Error Reporting and Logging

Structured Logging

Error Monitoring


Best Practices

1. Fail Fast

Validate inputs early and throw errors immediately for programming errors.

2. Be Specific

Use custom error types with context rather than generic Error.

3. Document Error Conditions

Specify what errors a function can throw in JSDoc.

4. Don't Swallow Errors

Always log or re-throw errors; never silently catch and ignore.

5. Provide Context

Include relevant information in error messages (what failed, why, what was attempted).

6. Use Type Guards

Check error types before handling:


Conclusion

Robust error handling requires:

  • Clear Error Types: Distinguish operational from programming errors

  • Explicit Handling: Use Result types or proper try-catch

  • Defensive Programming: Validate inputs and check nulls

  • Fault Tolerance: Implement retries, circuit breakers, fallbacks

  • Proper Logging: Structured logging with context

I apply these strategies across all my TypeScript projects for production-ready reliability.

What's Next?

References


Previous: ← Component Design | Up: Software Design 101 ↑

Last updated