3 ms·
visually the classical try-catch makes error handling right there more verbose and less readable. I far prefer Rust-like passing result with maybe adding contex
by ilyt 3y ago
visually the classical try-catch makes error handling right there more verbose and less readable. I far prefer Rust-like passing result with maybe adding context to the error along the way than try-catch block at every step of long process that have errors that should be handled in-place. Because passing it up is still easy, but adding any context is much less verbose.
> The only hard and fast rule is that any handling requiring human intervention should definitely be wrapped up and passed up.
The "wrapped up" being the important and mostly ignored part. From my experience try-catch error handling usually generates incomprehensible errors where you can only guesstimate what actually happened from stack trace's function names.
To get good error message every layer should have try-catch block that adds context to the error (what operation did it, or what logged user did it etc.), but that's almost never done properly and we get stack trace vomits instead.
If you want it to be fixed by actual humans you need to