On 24/03/2010, Gilles Sadowski <[email protected]> wrote:
> Hello.
>
> I'd like to suggest that there could be a nicer way to handle localization
> of error messages. Please have a look at
> http://cal10n.qos.ch/
>
> 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
> acceptable?
>
> 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 - 1]);
>
> A simple spelling mistake will defeat the purpose, as the localized version
> will not be found.
+1
> The above library takes care of this problem.
As would ordinary property files.
> 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.
>
> Best,
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]