commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <>
Subject Re: [math] OK to instanciate MathIllegalArgumentException directly?
Date Fri, 16 Dec 2011 11:58:48 GMT

> I'm still working on MATH-677, and would like to remove the
> IllegalArgumentExceptions thrown if the length of the data set is not
> a power of two. I was simply considering throwing
> MathIllegalArgumentException, but this is discouraged in the Javadoc.
> Can I break this rule, or should I create a NotAPowerOfTwoException
> subclass?

I wrote: "In most cases, [...]".

>From a practical viewpoint, I'd create a new subclass when the exception is
thrown from more than one place within CM. That avoids explicit referencing
to the lengthy "enum" element, and having to check and/or remember the order
of the arguments, as it is then taken care of inside the exception class.

>From a design viewpoint, a specific exception provides flexibility to the
caller, who can catch exceptions selectively (on the _type_, of course) for
the purpose of custom formatting an error message (or simply rethrowing
another exception) that better suits the application.
When all exceptions are just bare "IllegalArgumentException" objects, this
usage is impossible.

In the case which you mention, we could construe that "not a power of two"
is an implementation limitation that might be lifted (?) in the future. It
is an argument for not creating a class that would become useless at some
Your choice.


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

View raw message