Failures, mistakes and confusion

submited by
Style Pass
2024-04-16 15:30:04

I feel like there's quite a bit of confusion online in discussions of different "error handling models" in programming, and I think that it's probably because basically every "error handling model" in programming languages I've seen conflates two (or more!) separate concepts into a single system.

Failures happen when the system fails to perform some action, usually due to some constraint. Constraints could be physical (limited memory size), security (authentication), business (quotas), etc. Failures (almost always) cannot be proven to never happen in some code. They are usually explicitly communicated. They can often be worked around/fixed without human intervention. You usually handle them by either trying to work around and/or fixing the source issue of the failure, or communicating a failure yourself, depending on context and philosophy (fail-fast, etc).

Mistakes are faults in the code that break invariants, both explicit and implicit. Invariants are usually expressible with (some type of) logic. Large classes of mistakes can be proven to never happen in some code. They may be explicitly communicated when an invariant check fails, but sometimes it may result in an immediate effect without communication. It's usually undesirable to work around mistakes in code, and the largely preferred solution is to stop execution in a safe manner, stopping the propagation of the invariant breakage.

Leave a Comment