commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Ring <...@jdns.org>
Subject Re: [Math] About "NullArgumentException"
Date Tue, 11 Sep 2012 00:14:39 GMT
Hey Phil

On Mon, Sep 10, 2012 at 5:09 PM, Phil Steitz <phil.steitz@gmail.com> wrote:
> On 9/10/12 3:43 PM, James Ring wrote:
>>>  try {
>>>    // Call CM
>>>  } catch (NullPointerException e) {
>>>    // Handle NPE (raised by the JVM _or_ by CM).
>>>  }
>> Is this going to be the typical case? NPE indicates a programming
>> error, so this is something that *should* completely crash your JVM.
>
> Maybe I am being stupid here, but why is NPE so vastly different
> from, say, array index error and why is it bad to check parameters
> against documented preconditions and throw IAE when actual
> parameters do not meet the preconditions?   Do you think APIs should
> just "let the chips fall where they may" regarding invalid
> arguments, or do you think checking parameters and throwing IAE with
> an informative message is an acceptable practice?

I don't think NPE is different, you should check parameters against
preconditions and throw IAE as soon as you can. APIs should fail fast
so the stack traces are meaningful and errors are caught as early as
possible. Throwing IAE with an informative error is great.

Throwing an exception with a localized message seems pointless to me, FWIW.

> Phil

Regards,
James

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


Mime
View raw message