You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Anna Dymek (JIRA)" <ji...@apache.org> on 2015/04/27 11:37:39 UTC

[jira] [Commented] (THRIFT-727) support native language specific exception message

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

Anna Dymek commented on THRIFT-727:
-----------------------------------

I was working on resolving this issue and came up to the conclusion that this should be marked as "Won't fix" and closed - here are the reasons according to the issue decsription:

-- "It's a little confusing when to use the native method, and when to use Thrift exception message data member." - "message" is not Thrift exception's member, it's just the name of the field that a programmer declared in his custom exception. Somebody else can create an exception with completely different field names and it would be ridiculous to treat field "message" specially.

-- The straightforward idea that comes to mind is to generate the code that overrides what() method. However, the problem is - what should it return? Well, let's see the code for TProtocolException, which overrides what() method. It clearly returns the _reason_ why the exception was thrown. 
We can't generate code for every custom exception that will do it - we would only be able to return exception name (i.e. "MyException"), or all the field names & values (i.e. "MyException(code=4, message="Have a nice day")") - but this is either too little or probably too much information to include here.
Moreover, the programmer should be aware of what type of exception may be thrown in particular place. And if you want to see all the data members' values, operator << will print it all out. Including it again in what() will be code duplication.

------------------------
Summarizing: anything we can think of doing here occurs to be either impossible or a really bad coding practice, therefore I reason to close this task. However, if anybody has a better idea here, I'd be happy to implement it!

> support native language specific exception message
> --------------------------------------------------
>
>                 Key: THRIFT-727
>                 URL: https://issues.apache.org/jira/browse/THRIFT-727
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Compiler (General)
>    Affects Versions: 0.2
>         Environment: all
>            Reporter: Ping Li
>            Priority: Minor
>
> The current exception implement requires the error message to be declared and referenced explicitly, especially when it's sent from server to the client. On client side, this error message cannot be accessed via a native API like exception::what() in C++.
> Example,
> {code}
> exception MyException {
>   1: i32   code;
>   2: string message;
> }
> {code}
> On client side, it can only be accessed like this,
> {code}
> try {
>   server->someMethod();
> } catch (MyException &e) {
>   cout << "MyException: " << e.message << endl;     // this will print the exception message
>   cout << "MyException: " << e.what() << endl;      // this will print TException::Default
> }
> {code}
> At the same time, if TException::message_ is initialized, exception::what() does work when the exception is caught locally.
> It's a little confusing when to use the native method, and when to use Thrift exception message data member.
> It'll be really nice if all exception messages can be accessed the same way thru the navtive language on client side.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)