2 ms·
I get that and thats how I handle it too, however, you now have an IllegalArgumentException to handle for the null pointer when IMHO having null pointers should
by dkersten 17y ago
I get that and thats how I handle it too, however, you now have an IllegalArgumentException to handle for the null pointer when IMHO having null pointers should be something out of the ordinary and therefore not possible in MOST of the code.
- wlievens 17y agoThings 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.