back

by dcminter·13y ago·view on hn ↗
Exceptions are often used to catch unanticipated situations but they are also, legitimately, used to simplify common case logic by moving special case logic elsewhere.

"Exceptional" and "unanticipated" are not synonymous.

Edit:

I would add that it is true that there is a semantic burden with exceptions in that they are suggestive of error, rather than special case, conditions. So I would be very wary of using them in that way simply in my own code because it will potentially be misleading to consumers of the source code.

But if the clarity of the remaining code is sufficiently enhanced then it's a fair trade-off.

1 comments
I would add that it is true that there is a semantic burden with exceptions in that they are suggestive of error, rather than special case, conditions.

That depends very much on the idioms and conventions of whichever language you’re using. In Python, for example, there are some built-in exceptions like StopIteration that are used for routine flow control and do not in general represent an error.