[
https://issues.apache.org/jira/browse/THRIFT-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17936328#comment-17936328
]
Christopher Tubbs commented on THRIFT-3173:
-------------------------------------------
The default toString from Throwable should be fine, provided the code generates
a proper `getMessage()` implementation. This appears to be the same issue being
reported in THRIFT-3445
> 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
> Priority: Major
>
> 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
(v8.20.10#820010)