> From: Peter Royal [mailto:[EMAIL PROTECTED]] > > On Thursday, December 12, 2002, at 02:08 PM, Berin Loritsch wrote: > > 1) We should *never* explicitly throw a NullPointerException. > > If an argument is required, throw an IllegalArgumentException > > instead. The meaning of the error is much more clear. > > I'd actually prefer it the other way.. Why? > > Throw a NullPointerException when an argument that is > expected is null. > > Use IllegalArgumentException when there is an argument > supplied, but it > is invalid for other reasons.
When I see a NullPointerException coming from library code, I instinctively think that there is a serious problem with the *library* code and not my code. Any time there is a contract for the incoming parameters, and client code violates that contract, you should use the IllegalArgumentException. That lets the developer *using* your software to know they are in violation of an expected contract. With the RoleEntry class, it is an explicit contract (i.e. we are testing for the failure case) that no argument can be null. By using the IllegalArgumentException we don't get any confusion over what the _source_ of the error is. -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
