Hasty Briefsbeta

Bilingual

The Two Kinds of Error

2 days ago
  • #programming
  • #error-handling
  • #software-development
  • Errors in software are divided into two categories: expected and unexpected.
  • Expected errors occur during normal operation (e.g., invalid user input, network failures) and should be handled gracefully.
  • Unexpected errors indicate bugs (e.g., null pointer exceptions) and should crash the program to alert developers.
  • Expected errors should return error results and use WARN/INFO logs, while unexpected errors should use ERROR/FATAL logs.
  • The classification of errors as expected or unexpected depends on the context (e.g., prototype vs. mission-critical software).
  • Stricter languages (e.g., Rust) enforce handling expected errors, while looser languages (e.g., JavaScript) treat them as unexpected.
  • Handling errors properly improves software reliability and user experience.