Hi, everyone. I have a confusion. I build the tutorial of thrift (version 0.8) 
by java, input commands according to README:
        1, thrift/tutorial$ thrift -r -gen java tutorial.thrift
        2, thrift/tutorial/java$ ant
        3, thrift/tutorial/java$ ./JavaServer
        4, thrift/tutorial/java$ ./JavaClient

        output:
        server:
                Starting the simple server...
                Starting the secure server...
                ping()
                add(1,1)
                calculate(1, {DIVIDE,1,0})
                ...
        
        client:
                ping()
                1+1=2
                Whoa we can divide by 0
                15-10=5
                Check log: 5

When server execute "1 DIVIDE 0", I found "InvalidOperation" has been thrown in 
"CalculatorHandler.java" :
        InvalidOperation io = new InvalidOperation();
        io.what = work.op.getValue();
        io.why = "Cannot divide by 0";
        throw io;

But, it does not work. Server (JavaServer.java) returns struct, which contains 
exception (InvalidOperation) back to client, but when client execute "int 
quotient = client.calculate(1, work);", the exception (InvalidOperation) has 
lost. Client code:
    try {
      int quotient = client.calculate(1, work);
      System.out.println("result is:" + quotient);
      System.out.println("Whoa we can divide by 0");
    } catch (InvalidOperation io) {
      System.out.println("Invalid operation: " + io.why);    // would not be 
execute, but it should be when 1 DIVIDE 0
    }


So, I follow the code automatically generated by thrift with tutorial.thrift. I 
found the line "struct.setSuccessIsSet(true);" (line 2523 in Calculator.java) 
is the reason. If the line is be executed, client would receive success against 
exception (InvalidOperation).

Could anybody tell me why thrift do this?


Thanks a lot.

Bob Zhang

email: [email protected]  [email protected]
MSN: [email protected]

Reply via email to