2 ms·
If you were expecting an exception you'd want to catch, the situation isn't exceptional Here your argument starts applying to all exceptions, not just checke
by Confusion 17y ago
If you were expecting an exception you'd want to catch,
the situation isn't exceptional
Here your argument starts applying to all exceptions, not just checked exceptions. Consequently, the argument is obviously a hasty generalization, as breaking away from the regular flow of the code, by signaling an exceptional situation with a construction designed for that purpose, is a regular part of almost any programming language.
When is a situation exceptional? When it happens once a minute, once a day, once a year? That a situation isn't 'exceptional', according to you, doesn't mean you shouldn't want to use a special construction to signal that it is a special result. Firstly, it removes the burden to explicitly check the return value of every function call. If it returns, the function did its job. It increases the readability of code. Secondly, if you check the return value anyway, as often happens, 'special' cases of the regular return value, like 'null' or a special integer or string, always introduce problems. Problems of ambiguity, bookkeeping/documentation and unfortunate choices of the 'special' values are the most common ones. Exceptions a good solution to the problem it solves. Their downside is that they are easily abused.