thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Geyer" <jensge...@hotmail.com>
Subject Re: Why isn't TException a subclass of RuntimeException in Java?
Date Thu, 03 Sep 2015 18:37:15 GMT

I somehow overlooked that part of the equation => Agree with Randy.


-----Urspr√ľngliche Nachricht----- 
From: Randy Abernethy
Sent: Thursday, September 3, 2015 2:58 PM
To: user@thrift.apache.org
Subject: Re: Why isn't TException a subclass of RuntimeException in Java?

Hey All,

In Java TException is derived from the java Exception class. Per the Java
docs:

>> The class Exception and its subclasses are a form of Throwable that
indicates
>> conditions that a reasonable application might want to catch.

Sounds like what we want.

>> The class Exception and any subclasses that are not also subclasses of
>> RuntimeException are checked exceptions. Checked exceptions need to be
>> declared in a method or constructor's throws clause if they can be
thrown by
>> the execution of the method or constructor and propagate outside the
method
>> or constructor boundary.

So changing to RuntimeException as a base would make TException silently
throwable in Java, (which is the proposal).

In Apache Thrift, user defined exceptions which can be thrown from the
server
back to the client could then easily go uncaught. Also
TApplicationExceptions
which can always be thrown by a thrift server back to a client (even if the
user
doesn't define exceptions) could leak through. While I'm not a big fan of
Java
syntax, if your going to code in Java it seems like declaring throws
TException
is not a huge (or at least unusual) burden. In the greater scheme on things
making
an RPC call is a risky operation.

I was against this proposal until I began looking for idiomatic Java
behavior in
this area, where I found several examples using RuntimeException as the
base.
For example the javax.ws.rs.client.Invocation.invoke() method (used to make
REST calls in JAXRS) throws ResponseProcessingException which is unchecked.

java.lang.Object
    java.lang.Throwable
        java.lang.Exception
            java.lang.RuntimeException
                javax.ws.rs.ProcessingException
                    javax.ws.rs.client.ResponseProcessingException

So while I personally like the checked approach it seems we would be more
inline with common practice if we switch to RuntimeException as a base.

+0.5

-Randy

On Thu, Sep 3, 2015 at 2:45 AM, Jens Geyer <jensgeyer@hotmail.com> wrote:

> Some of the other languages actually do that. What about providing a 
> patch?
> ________________________________
> Von: J
> Gesendet: 02.09.2015 21:38
> An: user@thrift.apache.org
> Betreff: Why isn't TException a subclass of RuntimeException in Java?
>
> It seems tedious to have to mark every method that does a thrift rpc call
> with "throws TException" or have to put a try-catch around every call. Why
> wasn't TException made a subclass of RuntimeException? I think many RPC
> implementations I've used usually make the rpc/proxy errors runtime
> exceptions. There usually isn't anything you can do about it locally in 
> the
> client call anyway.
> 


Mime
View raw message