commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <>
Subject [Math] Localization and Error Handling
Date Wed, 24 Mar 2010 16:04:26 GMT

I'd like to suggest that there could be a nicer way to handle localization
of error messages.  Please have a look at

Of course, the first point that will be raised is that it creates an
external dependency. Is this a "no-no" or, given some benefits, could it be

Basically, I think that dealing with strings inside the math library code is
ugly and error-prone. E.g.

  throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range",
                                                            x, xval[0], xval[xval.length -

A simple spelling mistake will defeat the purpose, as the localized version
will not be found.
The above library takes care of this problem.

Even so, I think that *messages* should not appear at this level. It is much
simpler to use a set of specific exceptions. I.e. instead of the above
statement, one would use:

  throw new OutOfRangeException(x, xval[0], xval[xval.length - 1]);

where the exception is defined as

  public OutOfRangeException extends IllegalArgumentException {
     private double val, min, max;

     public OutOfRangeException(val, min, max) {
       this.val = val;
       this.min = min;
       this.max = max;

     public String getMessage() {
       // ... The string (or "enum" if using the "cal10n" library)
       // should appear at this level.

Admittedly, this means creating a lot of exception classes; but the
advantage is that they will allow more control.


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

View raw message