2

I'm working on a Thrift server which is basically just a wrapper around the Stanford Parser (although that's not too important). Sometimes the Stanford Parser will throw useful exceptions depending on the input it's given; for instance, if the input is too long (according to the parser), the user generating the input should receive this exception so they can decide how to handle it. However, I can't seem to get Thrift to pass this exception up, and instead only returns

Internal error processing <name of Thrift method being called>

to the client.

I have the following code in that method:

try
{
    // a whole bunch of Stanford Parser stuff
}
catch (Exception e)
{
    throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage());
}

and the method does throw a TApplicationException, but whatever the contents of e.getMessage() are are not being sent to the client. How can I get the exceptions being thrown by the Stanford Parser to be thrown by Thrift to the client?

dmn
  • 965
  • 3
  • 13
  • 24
  • 1
    In your thrift manifest did you specfy that the method can throw some exceptions? – darkheir Feb 27 '13 at 08:37
  • 1
    I would recommend the answer to this related question: http://stackoverflow.com/questions/11755292/how-to-use-java-built-in-exception-in-thrift-idl – dhal Feb 27 '13 at 20:02
  • Interesting...I had seen that question already but I didn't think that was what I was looking for. Maybe it is. And @darkheir, yes I have, but I've also tried taking that declaration out and it makes no difference. :/ – dmn Feb 28 '13 at 19:28

1 Answers1

0

I am afraid you have to define your own exceptions, instead of using TException or any subclass of it.

That's because Thrift framework wrap your code like this(ProcessFunction.java):

try {
  result = getResult(iface, args);
} catch(TException tex) {
  LOGGER.error("Internal error processing " + getMethodName(), tex);
  TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, 
    "Internal error processing " + getMethodName());
  oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.EXCEPTION, seqid));
  x.write(oprot);
  oprot.writeMessageEnd();
  oprot.getTransport().flush();
  return;
}

So, whatever message you give in TException, will be ignored and replaced by Thrift framework.

freeman
  • 399
  • 1
  • 3
  • 11