You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Trustin Lee <tr...@gmail.com> on 2005/09/01 02:02:53 UTC
Re: [OT] How best to respond to null arguments?
Hi Alex,
I usually choose option #2. Because null argument is usually unacceptable at
many situations.
But also consider replacing null argument with the default value silently.
:)
I don't recommend using assertion where there's an interaction with users
because it can be disabled by them.
Trustin
2005/9/1, Alex Karasulu <ao...@bellsouth.net>:
>
> Hi all,
>
> I was playing again with my very many split personalities when I
> realized one likes to throw NullPointerExceptions after checking if an
> argument is null while another likes to throw IllegalArgumentExceptions
> since null is value the argument can take. Yet another personality
> does not care and figures a NPE will result anyway when the null
> argument is referenced so why bother.
>
> Question: How best to respond to null arguments?
>
> Option #1: Ignore it and let a NPE result on its own
> Option #2: Test to see if arg is null early and throw a descriptive NPE
> Option #3: Test to see if arg is null early and throw a descriptive IAE
>
> Which sounds best?
>
> Alex
>
>
--
what we call human nature is actually human habit
--
http://gleamynode.net/