3 ms·
> Then wrap the error as many times as you want to annotate additional lines as the error is handled up to the top level I'd add that this is a last resort; er
by Cthulhu_ 2y ago
> Then wrap the error as many times as you want to annotate additional lines as the error is handled up to the top level
I'd add that this is a last resort; errors should be handled and resolved as close to where they occur as possible. Having them bubble up to a central error handler implies you don't really want to do anything with it.
- gf000 2y agoI would argue that in the majority of the cases that's the only reasonable behavior. I do agree that errors should be handled as close as possible to where they occured, but not any closer -- e.g. there is not much you can do within a library's functions if an unexpected error occured inside. It should be handled at whatever business code happens to call it. And in the worst case, they should bubble up to a central handler, that either outputs an 500 error, or an error dialog. Exceptions pretty much make this the sane/default behavior, with rust-like ADTs with syntax sugar being close.