I am not a huge fan of exceptions per se, but it’s important to understand that they are a heuristic for minimizing ‘worry’ about things that are unlikely. I am not saying it’s a good thing, I am saying it’s the way people naturally work. Let’s say there is a function that’s 20 lines long, and if you did a thorough analysis of possible error conditions, regardless of likelihood, you might come up with 50 or more. We…
50 error conditions in a 20-line function doesn't really sound even remotely realistic. Probably only 5 of the 20 lines are actually calling functions that might return errors, and in most cases, we don't care what type of error is being returned. So if we're talking about 5 error-checks in 20 lines, then yes, we absolutely should write code to address them from the start . I mean, I can understand not dealing with e…
Is the network up?
Is the connection to SQL up?
Did someone just turn off the SQL machine half way through the query?
Can we find the server?
Are there any rows?
Did the SQL compile?
Do I have rights on this table?
Have you just terminated me as a result of a deadlock?
Did you return a Null when I was expecting a value?
Did you return a float when I was expecting an int?
Did my value just overflow?
Did you just return 0 and I tried to use it in division?
Did I just try to access the session but some other idiot clear it?
Did I just try to call a method on an object that is in fact null?
And that's all possible in a three liner off the top of my head. I'm sure there's plenty more than that that are possible! I didn't even start on the file ones...