[
https://issues.apache.org/jira/browse/THRIFT-727?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14513851#comment-14513851
]
Konrad Grochowski commented on THRIFT-727:
------------------------------------------
I can see one situation in which overriding "what()" in C++ generated
exceptions could make sense - catching all errors via std::exception:
{code}
try {
performOperationsOnServer();
}
catch (const std::exception& e) {
std::cerr << "Unexpected error: " << e.what() << std::endl;
}
{code}
It's rather a bad practice not to catch method specific errors, yet it might be
used in some scratch code used in test client for service not maintained by
client creator. In such situations client might want to know better what went
wrong and "TException::Default" in log does not help a lot. I think that
overriding "what" in generated C++ exceptions to contain string like
"TException - MyException(code=4, message="Have a nice day")" is not that bad
idea - exeptions are usually small struct, so messages should be quite compact
and yet it would give 'test client writers' more information about 'how they
used service wrong'. Users experienced with given service will just use proper
per-case exceptions and their members.
As for better reason of exception: maybe message should state something like -
"TException - service thrown: RESULTS_OF_OBJ_DUMP"
Yet in C++ problems start with "what" returning "const char*"...
Also - this issue seems to focus on C++ implementation, I think it should
either be renamed (+1) or analysis of other languages should be performed (too
huge IMHO)
> 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)