You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Devin Avery (JIRA)" <ji...@apache.org> on 2017/03/10 15:49:04 UTC

[jira] [Commented] (THRIFT-3173) Exceptions should set the inherited message field

    [ https://issues.apache.org/jira/browse/THRIFT-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15905291#comment-15905291 ] 

Devin Avery commented on THRIFT-3173:
-------------------------------------

We should take this a step further and look at populating all of the default fields. For example in Java most exceptions allow you to specify a "cause". We should populate that as well when we can (and have constructors that get generated to accept causes).

> Exceptions should set the inherited message field
> -------------------------------------------------
>
>                 Key: THRIFT-3173
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3173
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Library
>            Reporter: Jens Geyer
>
> Exceptions generated from the IDL never call the inherited {{TException(string)}} CTOR. This leads to the problem, that catching a generic exception always ends up with a `null` message.
> instead, the result of the {{toString()}} method looks like a good default. However, Java requires the {{super(string)}} CTOR to be called first, before all members are set, so calling the {{super(string)}} CTOR late like in the following simple idea [will not work out|http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8.7], unfortunately:
> {code}
>   public Xception() {
>   }
>   public Xception( int errorCode, String message)  {
>     //this();  
>     this.errorCode = errorCode;
>     setErrorCodeIsSet(true);
>     this.message = message;
>     // call super(string) to set Exception.message
>     // THIS WILL NOT WORK
>     super(toString());  
>   }
> {code}
> One idea could be to generate an exception factory and to refactor the content of {{toString()}} into a (static) factory method. If someone has a better idea, feel free to discuss and/or provde a patch.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)