commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <>
Subject Re: [math] removing MathUserException
Date Mon, 05 Sep 2011 20:21:37 GMT
On 9/5/11 12:47 PM, Luc Maisonobe wrote:
> 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 ?

+1 to go ahead and do this.  The only downside is if any users have
built dependency on the previous setup or want to use and have us
propagate checked exceptions.  This is a major release and we can
make this change now.  I think the important thing to document is
that we will not swallow or wrap exceptions thrown by user code. 
User's can then decide what and where to throw and catch in their
own code.

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

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

View raw message