I am newbie on Thrift. After calling a Thrift API, I am always getting the problem of the exception which is "Default TException." On the server side, there is a defined exception: "Invalid_argument_error".
Invalid_argument_error exp;
std::string error_string = "Invalid Argument!";
exp.__set_what_UTF8(error_string);
throw exp;
and on catching it...
catch (Invalid_argument_error &e)
{
Invalid_argument_error t;
t.__set_what_UTF8(e.what());
}
Even if I set the reason of the exception, I am getting the reason wrongly on Thrift client. Any help would be appreciated.
When an exception is raised on the server end, then for it to be delivered to the client, there must be two things in place:
TException
If the first point is not satisfied, then in most cases you will receive an generic TApplicationException
at the client, or the connection may just get disconnected (there are some implementation differences in the libraries, this is in the process of being consolidated).
If the second point is not satisfied, assumed you are throwing an correctly derived exception, there will be no generated code in place to serialize or deserialize it. Hence you basically get the same result as above, but for a different reason.
From the docs linked above:
Functions [21] Function ::= 'oneway'? FunctionType Identifier '(' Field* ')' Throws? ListSeparator? [22] FunctionType ::= FieldType | 'void' [23] Throws ::= 'throws' '(' Field* ')'