You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ole Ersoy <ol...@gmail.com> on 2015/12/19 02:16:54 UTC

[math] ArithmeticUtils subAndCheck try catch

The (This is nit picky) ArithmeticUtils subAndCheck uses a message template that is meant for addition.  Should it catch and rethrow the exception with a subtraction template?  This is how the exception is thrown (Line 470):
https://github.com/apache/commons-math/blob/master/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b);

Cheers,
Ole



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


Re: [math] ArithmeticUtils subAndCheck try catch

Posted by Gilles <gi...@harfang.homelinux.org>.
On Fri, 18 Dec 2015 19:16:54 -0600, Ole Ersoy wrote:
> The (This is nit picky) ArithmeticUtils subAndCheck uses a message
> template that is meant for addition.  Should it catch and rethrow the
> exception with a subtraction template?  This is how the exception is
> thrown (Line 470):
> 
> https://github.com/apache/commons-math/blob/master/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java
> throw new
> MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, 
> -b);

My opinion is that there are too many "independent" messages that 
actually
describe related families of problems.
My approach has been to try and mix and match "elementary" blocks in 
order
to reduce the number of messages to be localized.
I admit that the end result is sometimes not very nice to read, but the 
idea
is to simplify the management of this unnecessarily huge list.
There must be a better way than manipulating those string templates...

In short, I would not like yet another message.  Personally, for lack 
of
a better messaging framework, I'd add a new exception:
   MathArithmeticOperationException extends MathArithmeticException { 
/** ... */ }
and its instantiation would be something like:
   new MathArithmeticOperationException(LocalizedFormats.ADDITION,
                                        LocalizedFormats.OVERFLOW, a, 
b);
or
   new MathArithmeticOperationException(LocalizedFormats.SUBTRACTION,
                                        LocalizedFormats.OVERFLOW, a, 
b);

Or, with the existing code, it is possible to add this information to 
the
"ExceptionContext".

Regards,
Gilles

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