3 ms·
I agree with your two examples (malloc failure and hard drive issue). > They are errors but trying to handle every little bit of how a computer can go wrong is
by dgellow 7y ago
I agree with your two examples (malloc failure and hard drive issue).
> They are errors but trying to handle every little bit of how a computer can go wrong is not really a feasible task, although you might be inclined to handle some.
Though, using error values, it's not that different.
1. check if the error is something that you care about
2. if not, check if it is something that you should pass back to the caller (in general that's an assert "if not null/empty"), if it is then return it
3. otherwise continue what you're doing in the current function
You have the same result without a need for exception, you only handle what you care about in the current scope, or let the chain of callers decide what they want to do with the error.
- saagarjha 7y agoExceptions are basically sugar for that, since this kind of thing is done so commonly that it’s useful to have a construct for it.
- Reelin 7y agoIt's too easy to forget to check or propagate an error value (in most languages) though. Exceptions are nice because you can't forget - you either handle it somewhere in the call stack or the process is killed.