Hello,

I took a closer look at the exception behavior for each module and I did 
discover an inconsistency in the RegularizedGamma.P.value() method in the 
commons-numbers-gamma module. In some cases, the code would delegate to 
RegularizedGamma.Q.value(), which uses a subclass of ContinuedFraction (from 
commons-numbers-fraction) to evaluate the result. This class throws an 
ArithmeticException when the continued fraction fails to converge. However, in 
other cases, RegularizedGamme.P.value() evaluates the result directly, this 
time throwing a GammaException (subclass of IllegalArgumentException) if it 
fails to converge. So, in some cases, we throw an ArithmeticException and in 
other cases an IllegalArgumentException on convergence failure. I fixed this by 
throwing an ArithmeticException if the directly evaluated expression fails to 
converge. This is consistent with the classes in commons-numbers-fraction, 
which all throw ArithmeticExceptions on convergence failure.

This change is in a PR on Github [1]. I've also fixed a number of missing or 
incorrect "@throws" parameters in the documentation. All other exception 
behavior looks consistent.

-Matt

[1] https://github.com/apache/commons-numbers/pull/74
________________________________
From: Miguel Munoz <swingguy1...@yahoo.com.INVALID>
Sent: Monday, February 3, 2020 10:24 PM
To: Commons Developers List <dev@commons.apache.org>
Subject: Re: [numbers] NUMBERS-40: Exception Consistency

Maybe some examples would be helpful.

-- Miguel Muñoz






On Sunday, February 2, 2020, 02:17:29 AM PST, Gilles Sadowski 
<gillese...@gmail.com> wrote:





Hi.

2020-01-26 16:54 UTC+01:00, Matt Juntunen <matt.juntu...@hotmail.com>:
> Hello,
>
> I'm looking into NUMBERS-40, which suggests that the exception behavior of
> commons-numbers (specifically the gamma package) needs to be made more
> consistent. Below is a summary of the public exception types explicitly
> thrown by each module.
>
> arrays
>        IndexOutOfBoundsException
>        IllegalArgumentException
>
> combinatorics
>        IllegalArgumentException
>        NoSuchElementException
>        UnsupportedOperationException
>
> complex
>        NumberFormatException
>        IllegalArgumentException
>
> complex-streams
>        IllegalArgumentException
>
> core
>        ArithmeticException
>        IllegalArgumentException
>
> fraction
>        ArithmeticException
>        IllegalArgumentException
>
> gamma
>        IllegalArgumentException

Some methods throw "ArithmeticException" while others throw
"IllegalArgumentException".  IIRC, my issue was whether there
were cases where the behaviour is not consistent from a
user POV (IOW, where the same behaviour would be expected).

[Note: I did not review all the packages.  But I don't recall there
were this kind of issue.]

Gilles


>
> primes
>        IllegalArgumentException
>
> quaternion
>        NumberFormatException
>        IllegalArgumentException
>        IllegalStateException
>
> rootfinder
>        IllegalArgumentException
>
>
> Nothing in this list strikes me as being inconsistent. The types are all
> standard JDK exception types and seem to be used appropriately, IMO. Is
> there any work that needs to be done on this issue?
>
> Regards,
> Matt J

>
>
>

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



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

Reply via email to