NullPointerException vs IllegalArgumentException
Cameron Taggart
cameron.taggart at gmail.com
Thu Jan 6 11:20:55 EST 2005
+1 for NullArgumentException
On Thu, 6 Jan 2005 17:46:54 +0900, David Leangen <dleangen at canada.com> wrote:
>
> That sounds right. I've been using NPE myself, but I like your suggestion of
> a NAE better.
>
> Cheers,
> Dave
>
>
> > -----Original Message-----
> > From: dev-dpml-bounces at lists.ibiblio.org
> > [mailto:dev-dpml-bounces at lists.ibiblio.org]On Behalf Of Niclas Hedhman
> > Sent: 6 January 2005 16:28
> > To: DPML Development
> > Subject: NullPointerException vs IllegalArgumentException
> >
> >
> >
> > Gang,
> >
> > Steve and I have different opinions about what to throw when a
> > null argument
> > is passed into a method that doesn't accept it.
> >
> > His style is;
> >
> > if( abc == null )
> > throw new NullPointerException( "abc" );
> >
> > whereas my style is;
> >
> > if( abc == null )
> > throw new IllegalArgumentException( "Null argument: abc" );
> >
> > Instead of tossing this issue back and forth (I will claim that the JDK
> > javadocs clearly states "Thrown to indicate that a method has
> > been passed an
> > illegal or inappropriate argument.") , and Steve will say "NPE is
> > preempted
> > in time" and "xxx throws it in the JDK", I would like to propose
> > that we make
> > a reasonable compromise;
> >
> > public class NullArgumentException extends IllegalArgumentException
> > {
> > }
> >
> > and put that into the Util package.
> >
> > and that the patter is;
> >
> > if( abc == null )
> > throw new NullArgumentException( "abc" );
> >
> > I picked up the pattern from the Geronimo folks, and it made
> > perfect sense to
> > me. The checks for null arguments are extensive, so I think it
> > validates an
> > explicit exception, the IllegalArgumentException semantic is
> > honored and can
> > not be misunderstood.
> >
> > The switch over can also happen gradually whenever we have time
> > and is of no
> > urgency whatsoever.
> >
> >
> > WDYT?
> >
> > Cheers
> > Niclas
> > --
> > ---------------
> > My mechanic told me, "I couldn't repair your brakes, so I made your horn
> > louder."
> > - Steven Wright
> >
> > +---------//-------------------+
> > | http://www.dpml.net |
> > | http://niclas.hedhman.org |
> > +------//----------------------+
> >
> > _______________________________________________
> > dev-dpml mailing list
> > dev-dpml at lists.ibiblio.org
> > http://lists.ibiblio.org/mailman/listinfo/dev-dpml
>
> _______________________________________________
> dev-dpml mailing list
> dev-dpml at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/dev-dpml
>
More information about the dev-dpml
mailing list