commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <>
Subject Re: [math] right way to throw IndexOutOfBoundsException?
Date Mon, 08 Aug 2011 06:38:32 GMT
On Sun, Aug 07, 2011 at 10:47:41PM -0700, Phil Steitz wrote:
> I was about to do this:
> throw MathRuntimeException.createArrayIndexOutOfBoundsException(
>                     LocalizedFormats.OUT_OF_RANGE_SIMPLE, index, 0,
> parameters.length);
> but remembered that this is now deprecated.  Do I need to add a
> MathArrayIndexOutOfBoundsException extending the JDK exception and
> then throw that directly?  

Do we really want to subclass all Java exceptions?
There was a discussion where I thought that we circumscribed all the types
of problems that would need CM exceptions to sublcass the standard ones.

Cases such as this would fall in the "illegal argument" category.

  throw new OutOfRangeException(index, 0, parameters.length);

or, to get a more detailed message,

  OutOfRangeException e = new OutOfRangeException(index, 0, parameters.length);
  e.addMessage(INDEX, index);
  throw e;

Of course, "OutOfRangeException" cannot inherit from both
"IllegalArgumentException" and "IndexOutOfBoundsException"...


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message