I favour IAE myself as a guideline though wouldn't rule against NPE in
some code.
On Thursday, August 14, 2003, at 09:25 am, Alex Blewitt wrote:
On Thursday, Aug 14, 2003, at 07:57 Europe/London, James Strachan
wrote:
On Thursday, August 14, 2003, at 06:31 am, Aaron Mulder wrote:
Maas,
egarding this particular patch, I'd prefer that we don't actually
add "null" to the list of DeploymentFactories, even if it's passed
as an
argument to DeploymentFactoryManager.registerDeploymentFactory().
That's
silly, we should just ignore a null.
Failing fast with silly arguments is a good idea - e.g. throw an
IllegalArgumentException or NullPointerException.
I've never liked the idea of a method throwing an NPE when passed a
null argument. A bunch of the Java data structures do this, and I've
had pains when they do so.
An NPE (to me) means a coding bug, usually requiring a lot of hard
work figuring out where it came from and why it exists
An IllegalArgumentException means that a method has been passed a
wrong value (i.e. value out of range, string in wrong format, null
value passed when arg was required), and usually has some kind of
error message associated with it.
Go on, tell me which you'd prefer to see in the logs:
[Exception] NullPointerException
[Exception] IllegalArgumentException: address must not be null
Alex.
PS Votes for saying 'never throw NPEs in methods; use IAE instead?' in
the coding standards?
James
-------
http://radio.weblogs.com/0112098/