Hasty Briefsbeta

Vexing Exceptions

17 hours ago
  • #error-handling
  • #programming-best-practices
  • #exceptions
  • Error handling in programming involves classifying exceptions into four categories: fatal, boneheaded, vexing, and exogenous.
  • Fatal exceptions (e.g., out of memory) cannot be prevented or cleaned up; they indicate a deeply diseased process.
  • Boneheaded exceptions (e.g., null reference) are preventable bugs in your code; they should be fixed rather than caught.
  • Vexing exceptions result from poor design (e.g., Int32.Parse failing on user input); they must be caught but are frustrating.
  • Exogenous exceptions arise from external factors (e.g., file not found); they must be handled due to unpredictable real-world conditions.
  • Best practices include not catching fatal exceptions, preventing boneheaded exceptions, avoiding vexing exceptions, and handling exogenous exceptions.
  • Exceptions should generally be thrown for boneheaded and exogenous scenarios but avoided otherwise.
  • A debate exists on whether to catch OutOfMemoryException in specific cases like image caching, with arguments for and against.
  • The distinction between vexing and exogenous exceptions lies in their origin: vexing exceptions stem from poor design, while exogenous ones come from external chaos.