Hello. > 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 point. Your choice. Regards, Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org