3 ms·
How is it supposed to know how you want your errors handled by default? Handling errors is the programmer's job.
by oopsallmagic 2y ago
How is it supposed to know how you want your errors handled by default? Handling errors is the programmer's job.
- Too 2y agoThere are lots of techniques to make it obvious that errors can happen and need to be handled. 1. Make it difficult to ignore that a function can return an error. This is the golang approach. Errors are part of the return values and unused return values are compiler errors. 2. Make it impossible to use parts of the return value having an error state. Rust does this with the Result sum type and pattern matching. 3. Tailor for the happy-path and throw exceptions in case there are any errors. With optional means to catch them if recovering errors is desired. This is how most other languages function. Hiding the error status in another variable, that is super easy to overlook and that the programmer might not even know exists, then continuing despite this variable not being checked will inevitably introduce bugs allowing faulty data in your system.