Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5333

Exceptions defined in IDL to extend Exception rather than TException

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Works for Me
    • Affects Version/s: 0.13.0
    • Fix Version/s: None
    • Component/s: Java - Compiler
    • Labels:
      None

      Description

      At the moment, if an exception is defined in IDL and Java code is generated for it, the exception would be defined as extending TException like this:

      public class MyException extends org.apache.thrift.TException implements ...
      

      At the same time, definition of methods looks like this:

      public int myMethod(int argument) throws MyException, org.apache.thrift.TException {
      ...
      }

      Here, TException has to be included as that is the only way to signal that RPC call has failed for whatever reason.

      Now the problem with this is that if one calls a method like that, it is obvious that TException covers all those exceptions defined in IDL and so there is no way to clearly see which exceptions are result of internal workings of Thrift and which ones correspond to situations described in IDL:

      try {
        myMethod(123);
      } catch (TException e) {
        log.error("Problem spotted", e);
      }

       

      Why not make extensions extend java.lang.Exception instead?

      public class MyException extends java.lang.Exception implements ...

      This would have made it clear which exceptions are throwable by the call as "catch (TException e)" would not catch them and explicit catching would be in order:

      try {
       myMethod(123);
      } catch (MyException e) {
       log.error("MyException has been thrown");
      } catch (TException e) {
       log.error("Problem spotted", e);
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jensg Jens Geyer
                Reporter:
                Rtveliashvili Denys Rtveliashvili
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: