William Brogden wrote:I would certainly throw IllegalArgumentException and include a helpful message if possible. Much more informative than NPE
William Brogden wrote:I would certainly throw IllegalArgumentException and include a helpful message if possible. Much more informative than NPE - consider the work you would have to do with an NPE to figure out what happened.
Campbell Ritchie wrote:
Paul Anilprem wrote:To me, there is one major issue with throwing NPE and ArrayIndexOutOfBoundsException. These exceptions indicate that the violation has already occurred...
Agree with MS. The problem with nulls is that you cannot tell what is null. A programmer can tell what is happening if you write this sort of thing… but it may be impossible for the JVM to do so. The local variable and parameter identifiers are not reflected in the bytecode, so it is often impossible for the JVM to throw an NPE and say “x is null in Foo.java line 12345”
Mike Simmons wrote: . . . it's pretty much the standard within all the Sun/Oracle libraries to use an NPE in this case - usually with no useful message, . . .
Campbell Ritchie wrote:Maybe I shall agree with whoever writes, “Who cares what sort of Exception you use, as long as you have a good error message to go with it.”
Effective Java wrote:NullPointerException : Parameter value is null where prohibited.
IllegalArgumentException : Non-null parameter value is inappropriate.