You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles (JIRA)" <ji...@apache.org> on 2011/03/06 15:15:25 UTC

[jira] Created: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Allow the addition of multiple messages to the exceptions generated by CM
-------------------------------------------------------------------------

                 Key: MATH-542
                 URL: https://issues.apache.org/jira/browse/MATH-542
             Project: Commons Math
          Issue Type: New Feature
            Reporter: Gilles
            Assignee: Gilles
            Priority: Minor
             Fix For: 3.0


Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.

The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
{code}
/**
  * Sets a message.
  *
  * @param pattern Message pattern.
  * @param arguments Values for replacing the placeholders in the message
  * pattern.
  */
  public void addMessage(Localizable pattern,
                         Object ... arguments);
{code}


-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003193#comment-13003193 ] 

Gilles commented on MATH-542:
-----------------------------

I think that the most interesting use of the new functionality (as I see it) might be to do away with exception wrapping. In particular, this would apply in the controversial example in "ContinuedFraction". 
We don't need a "ConvergenceException": A high-level message (conveying convergence failure) can be attached to the low-level exception (description of the failure).


> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gilles resolved MATH-542.
-------------------------

    Resolution: Fixed

> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003190#comment-13003190 ] 

Gilles commented on MATH-542:
-----------------------------

Of course an object like "ExceptionContext" could store arbitrary (key, value) pairs.
But if users want to use "ExceptionContext", they can use the real thing ;-) i.e. depend on [Lang] for that functionality. We don't need that _in_ CM.
What we need to do in CM is provide a fully informative localized message. I know it is a burden for users to implement "Localizable" but, IIRC, you said that you were doing exactly that in your application (because you need localization).
So to achieve that goal in the simplest way, "addMessage" is all that's needed.
Allowing arbitrary types for the key will go in the way of the above goal. Indeed, how do you localize the message string if you don't have a "Localizable" key? I know that we _could_ do it (with "instanceof") but I think that we wouldn't do a favour to CM users: When some code layers insert non-localizable messages/objects, it will result in a patchwork of different languages in the final display. And if we don't display the non-localizable info, then we contradict part the stated goal (full information).

Again, I recommend to keep it simple at first, until a clear-cut use-case shows that some functionality is missing.


> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003209#comment-13003209 ] 

Luc Maisonobe commented on MATH-542:
------------------------------------

No, users can't use [lang] ExceptionContext on [math] exception if [math] does not provide the same feature.
The key-value pairs are more general than Localizable-arguments and they may be used for something different than building a message.

I don't intend to suppress the Localizable-arguments part, just to add the possibility to add key-values. We could even use this to hold the Localizable and the arguments array if we want. So an exception would have at least the localizable and the arguments (enforced by constructor) but also additional parameters. Some of these parameters would be directly injected by [math] for some specific exceptions (iteration count, out of bound value ...) but the user could add its own, thus effectively removing some of the use of wrapping. The additional parameters are not intended to appear in the message, so there would not be a patchwork of languages in the final display.

The typical use case I have (from my own code) is something like a spacecraft maneuver planning algorithm that do call an optimizer from [math]. If the optimizer fails, we get some [math] exception. We just catch it, add some information about the context of the maneuver planning and throw the same exception again for the top level to catch it and react on the context information and decide if it can make another try (for example switch to another propulsion mode) or if it should give up and display the original exception (most of the time without its context, because when we decide to give up we want to display something more general than the context of the last attempt only).

> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003177#comment-13003177 ] 

Luc Maisonobe commented on MATH-542:
------------------------------------

I don't think we want to add messages, but key-value pairs.
In [lang] the methods in interface ExceptionContext are:
{code}
public ExceptionContext addValue(String label, Object value);
public Object getValue(String label);
{code}
The purpose is that upper layers can propagate information from one level to an upper level

> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003319#comment-13003319 ] 

Gilles commented on MATH-542:
-----------------------------

Implementation committed in revision 1078734.

One further simplification would be to remove the constructor that allows wrapping of exceptions, but there might be cases where wrapping will still be useful.


> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003182#comment-13003182 ] 

Gilles commented on MATH-542:
-----------------------------

Do you really want to allow "String" keys?
My understanding was that we would allow the addition of "Localizable"s. This is a direct adaptation of the concept but satisfying the requirement of CM.

The "getValue" is not useful for CM because the intended goal is the display of the message (as a localized string). We don't need the added flexibility of retrieving unprocessed patterns. Those should remain implementation details.

The map feature enhances the stack trace by indeed allowing to provide additional messages when the exception travels up the stack. Similarly to the stack trace, this info should remain ordered with respect to the call chain, resulting in a final message such as
---
original cause: more info added: some more info added by an intermediate call: last message added before display
---
[The ": " is the separator inserted between each bit of info added through "addMessage".]


> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003220#comment-13003220 ] 

Gilles commented on MATH-542:
-----------------------------

So, IIUC, there would be two kinds of storage:
* one for localizable messages
* one for any kind of values represented by a (key, value) pair where the value can have any type (thus "Object")

And only the first kind will contribute to the compound message.
Is that so?

I would then add those methods:
{code}
public void setContext(String key, Object value);
public Object getContext(String key);
public Set<String> getContextKeys();
{code}
[Don't you think that a key of type "Object" is unnecessarily general? I also wonder how upper layers will even make sense of a given key if they don't know what type it is.]


> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005071#comment-13005071 ] 

Gilles commented on MATH-542:
-----------------------------

"readObject" and "writeObject" methods implemented (revision 1080231), following Jörg's suggestion on the ML.


> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003186#comment-13003186 ] 

Luc Maisonobe commented on MATH-542:
------------------------------------

{quote}
Do you really want to allow "String" keys?
{quote}

I would even allow Object keys.

{quote}
My understanding was that we would allow the addition of "Localizable"s. This is a direct adaptation of the concept but satisfying the requirement of CM.
{quote}
This is more cumbersome for users. If they only want to have a key, requiring them to implement the Localizable interface is overkill.

{quote}
The "getValue" is not useful for CM because the intended goal is the display of the message (as a localized string). We don't need the added flexibility of retrieving unprocessed patterns. Those should remain implementation details.
{quote}
My understanding was that the intended goal was not to display message (of course it could be used for that), but rather to get some values. In fact I saw it as a more fine grained version of our existing getArguments() method from MathThrowable, with the additional benefit to retrieve a specific argument from its key.

{quote}
The map feature enhances the stack trace by indeed allowing to provide additional messages when the exception travels up the stack. Similarly to the stack trace, this info should remain ordered with respect to the call chain, resulting in a final message such as
—
original cause: more info added: some more info added by an intermediate call: last message added before display
—
[The ": " is the separator inserted between each bit of info added through "addMessage".]
{quote}
With this behaviour, the key-values pairs would only be used for messages building. I think the ExceptionContext feature from [lang] goes beyond that.

> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (MATH-542) Allow the addition of multiple messages to the exceptions generated by CM

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003290#comment-13003290 ] 

Luc Maisonobe commented on MATH-542:
------------------------------------

This seems fine to me.
We can restrict keys to String.

thanks!

> Allow the addition of multiple messages to the exceptions generated by CM
> -------------------------------------------------------------------------
>
>                 Key: MATH-542
>                 URL: https://issues.apache.org/jira/browse/MATH-542
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Gilles
>            Assignee: Gilles
>            Priority: Minor
>              Labels: api-change
>             Fix For: 3.0
>
>
> Borrowing on the idea of "ExceptionContext" implemented in [Lang], "MathRuntimeException" (base class of all exceptions generated from CM) will be enhanced so that an unlimited number of (localized) messages can be added to an exception object.
> The "MathThrowable" interface (implemented by "MathRuntimeException") will contain the following new method:
> {code}
> /**
>   * Sets a message.
>   *
>   * @param pattern Message pattern.
>   * @param arguments Values for replacing the placeholders in the message
>   * pattern.
>   */
>   public void addMessage(Localizable pattern,
>                          Object ... arguments);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira