3 ms·
Things that are not possible should be asserted to be so. Leaving an assumption in the mind of the programmer only is dangerous and almost worthless. Any assump
by wlievens 17y ago
Things that are not possible should be asserted to be so. Leaving an assumption in the mind of the programmer only is dangerous and almost worthless. Any assumption reasonably expressible in code should be expressed in code. This goes beyond null checks, it counts for any state.
For instance, in a tool that uses graphs as data structures, some transformations might impose that your graph at input and output is acyclic. Don't put this in comments, assert it in code!
The exception is an exception in the strictest sense: something that should not happen. I consider IllegalArgumentException to be an exception you should never catch (except in unit tests, perhaps), but instead fix the root cause. Unlike IOException for instance.