Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-487

Deprecate "ConvergenceException" in MATH_2_X and remove it in trunk

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0
    • None
    • None

    Description

      The checked "ConvergenceException" should be deprecated.

      An example usage is in class ContinuedFraction (package util), at line 153:

        if (scale <= 0) {  // Can't scale
          throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE, x);
        }
      

      I think that it should be replaced by a more specific (and unchecked) exception that reflects the exact low-level problem:

        if (scale <= 0) {  // Can't scale
          throw new NotStrictlypositiveException(scale);
        }
      

      A few lines below that, there is:

        if (infinite) {
          // Scaling failed
          throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE, x);
        }
      

      So it seems that it is not necessary to throw an exception at the place where the test on "scale" fails; instead we could have:

        infinite = true;
        if (scale <= 0) {  // Can't scale
          break;
        }
      

      and let the check on "infinite" throw the exception:

        if (infinite) {
          // Scaling failed
          throw new NotFiniteNumberException(LocalizedFormats.CONTINUED_FRACTION_DIVERGENCE,
                               Double.POSITIVE_INFINITY, x);
        }
      

      As shown in the above excerpt, we could also replace two enum:

      • CONTINUED_FRACTION_INFINITY_DIVERGENCE
      • CONTINUED_FRACTION_NAN_DIVERGENCE

      with a single one:

      • CONTINUED_FRACTION_DIVERGENCE

      because the other bit of information (infinity vs NaN) is already given by the first parameter of the message.

      What do you think of these changes?

      Attachments

        Activity

          People

            Unassigned Unassigned
            erans Gilles Sadowski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: