How come C++ and Java servers differ in their handling of standard exceptions?
The generated C++ service code catches std::exception and turns it into a
TApplicationException and passes it back to the client. In contrast, the
generated Java service code does nothing like this. In particular, if a Java
server encounters a RuntimeException, it is not handled. The result is the
client gets a cryptic TConnectionException with no indication of the problem.
Shouldn't the generated Java server code behave more like the C++ server?
You can see this in the code generated for the tutorial example. If you look
at the generated Calculator.cpp code for the C++ server, you will see that
every process_* method includes catch blocks for std::exception. These catch
blocks do the conversion to TApplicationException. But when you look at the
Java server code in Calculator.java, the getResult methods don't have any such
catch blocks for RuntimeExceptions.
The upshot is that for Java servers to throw useful RuntimeExceptions like
IllegalArgumentException requires the user to declare that every method throws
a custom exception, then wrap every method implementation with boilerplate to
catch RuntimeExceptions and translate them to the custom exception. This is
onerous and error prone. Since the C++ server does it automatically, I think
the Java server should as well.
Thrift-378 seems to address this issue. The conclusion is that it was fixed.
However, it obviously is not.
-craig