Or maybe they are the ultimate logicians – but they are still idiots. Even logic is not universally applicable in black and white.
For example the humble “null”. Day one of java school specifically states: “See a null, throw an exception – it must be wrong”
An enlightened language, for example PHP, will treat a null in the same way as zero, false, and an empty string during general operational mode. If you want to go into EXCEPTION based logic, you can detect null with an equivalence check. Why is this good? well, for a start, the whole point about EXCPETIONs is the fact they are an EXCEPTION to the standard business logic, which means you have to understand what you’re trying to do at any particular point.
Take an address for example, just because it does not have a postcode does not make it invalid – well unless you live in Ohio. A postcode not being present in a UK system could be an indicator of several things
- an overseas country.
- someone who has forgotten their postcode.
- someone who just moved house and doesn’t know their postcode.
- someone talking on behalf of someone else and not knowing their postcode.
If you wrote a letter and didn’t put the postcode on it, would the Post Office put the letter in the bin? No… well, they may do where I live, but generally NO!
Now, what if your system were tracking usage by postcode… well, this is a different kettle of digits. If you’re tracking usage of something by postcode then you would generally expect there to be one. In the event a postcode is missing you have 2 options. Either log the fault and move on (i.e. it’s important to log whatever you are doing, but add a bin for “Unknowns”), or it’s not important in which you can stop what you’re doing and do the next one (an exception can be used here).
An exception (in my not so humble opinion) is a glorified GOTO command that basically gets you round some error checking and nested IF’s… would you use a GOTO in your code? no. (Well hopefully not anyhow).
Exceptions are not a lazy alternative to proper error checking.
