commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@gmail.com>
Subject Re: [lang] NullArgumentException usage
Date Thu, 07 Jul 2011 17:11:05 GMT
On Thu, Jul 7, 2011 at 11:56 AM, Gary Gregory <garydgregory@gmail.com> wrote:
> Hi All:
>
> I do like using NullArgumentException, but I find writing this over and over
> tedious:
>
> if (arg == null) {
>  thrown new NullArgumentException(argName);
> }
> something(arg);
>
> How about this instead:
>
> NullArgumentException.check(arg, argName);
> something(arg);
>
> or:
>
> something(NullArgumentException.check(arg, argName));
>
> Depending on the style you like.
>
> Where check is:
>
>    public static <T> T check(T arg, String argName) {
>        if (arg == null) {
>            throw new NullArgumentException(argName);
>        }
>        return arg;
>    }
>
> Yes, you are pushing the argName on the stack (or passing it in a register)
> and that is extra work, but you do not have to use the new method then ;)
>
> ?

Notice that NullArgumentException doesn't live in [lang] v3.  :|

Matt

>
> --
> Thank you,
> Gary
>
> http://garygregory.wordpress.com/
> http://garygregory.com/
> http://people.apache.org/~ggregory/
> http://twitter.com/GaryGregory
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message