commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hendriks, D." <D.Hendr...@tue.nl>
Subject RE: [math] removing MathUserException
Date Mon, 05 Sep 2011 21:18:41 GMT
> What do you think ?

Sounds good Luc!

Best regards,
Dennis

________________________________________
Van: Luc Maisonobe [Luc.Maisonobe@free.fr]
Verzonden: maandag 5 september 2011 21:47
Aan: Commons Developers List
Onderwerp: [math] removing MathUserException

Hello,

Cleaning out the ode package, I have seen that we throw ourselves a
MathUserException when the max number of allowed evaluations was
exceeded. I have fixed that in my local copy (not committed yet) and
used the opportunity to replace the ad hoc code by the new Incrementor
class, which purpose is precisely to count things and throw a dedicated
exception (MaxCountExceededException) if needed. This also allowed to
remove the last use of MaxEvaluationExceededException and hence the
exception itself (which was still in the top level package).

As I wrote a few hours ago answering a question from Dennis, we can now
get completely rid of MathUserException in the ode package. I have also
done that and checked everything worked well. The idea behind this was
discussed some months ago if I remember well. It was simply that users
should better use their own unchecked exception, so they can be sure
[math] will never catch them, when they call [math] code which itself
call their functions back (like in ODE, root solvers, optimization ...).
The current behavior with MathUserException was not really clean since
we did throw it by ourselves (at least in ODE, which I removed). As an
example, some clean user code should be:

public class Myclass implements FirstOrderDifferentialEquation {
   private static class LocalException extends RuntimeException {
     public LocalException(int a, int b, int c) {
        // store some information about a, b, c
     }

     // some getters go here

   }

   public void solveODE() {
      try {
          integrator.integrate(this, t0, y0, t, y);
      } catch (LocalException le) {
         // retrieve the a, b and c values
      }

   }

   public int getDimension() {
     return 3;
   }

   public void computeDerivatives(double t, double[] y, double[] yDot) {

      // compute things

      if (somethingBadHappens) {
        throw new LocalException(a, b, c);
   }

}

As shown in this exemple the exception is really something local to user
code and there is a guarantee [math] will not mess with it. The user is
safe.

I would like to finish implementing this for ODE (i.e. simply commit
what I have already done), and to extend it to the rest of [math],
completely removing MathUserException. I would also document this as a
general rule for [math] users (using the example above).

What do you think ?
Luc

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


Mime
View raw message