2 ms·
An exception allows you to handle exceptional errors at any level, without having to handle errors, or write a single line of code, at every other level. You ca
by nomel 2y ago
An exception allows you to handle exceptional errors at any level, without having to handle errors, or write a single line of code, at every other level. You can assume perfection, and put that catch at the level of the abstraction where there's an actual concern for the exceptional, keeping all the other code simple.
I've always worked strongly in the physical world side of software, like network stacks, test equipment, robots, etc, so I can't see a sane alternative, that doesn't involve in increasing the LOC by 20%, and being error prone (it's trivial to accidentally eat an exception if you're relying on returned values).
If you don't want to bubble up the exception to the user, that's trivial too. You just catch it at whatever level you choose, handle whatever, then return something nice.