Jens Geyer created THRIFT-3173: ---------------------------------- Summary: 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.4#6332)