3 ms·
Yes, this is an easier mistake to make with exceptions than with error values. Still, the fix is to do exactly the same thing as in the error values case: tr
by simiones 6y ago
Yes, this is an easier mistake to make with exceptions than with error values. Still, the fix is to do exactly the same thing as in the error values case:
try {
someCall()
} catch (ErrorType err) {
//handle one way
}
try {
someOtherCall()
} catch (ErrorType err) {
//handle another way
}
It's no less verbose than the error values way, though again, it is easier to make the mistake in the first place.
I'm not trying to claim that exceptions are ultimately better than error values, just that the difference isn't so much "non-local control flow" as it is explicitness vs implicitness. Exceptions are implicit, error codes are explicit. Both have benefits and drawbacks.