Exceptions don't exist in grpc; you won't see an exception propagate from server to client. Instead, grpc uses Status, which has a enum "code" and a string "description". StatusRuntimeException and StatusException are part of the stubs to allow using grpc in an idiomatic way in Java. StatusException is a checked exception, and the blocking stub is not marked as throwing any checked exceptions, so the blocking stub must use StatusRuntimeException.
On Thu, Jul 14, 2016 at 7:02 PM, 王 梓佳 <[email protected]> wrote: > Dear team, > > I'm studying the error handling from the example below. I just specified > the exception type in place *(1)* as I want to the server side to throw a > checkable exception, but the caller side always receive the > StatusRuntimeException no matter what type of exception is specified in > Status in server side. Anything went wrong or my assumption is not correct? > > > https://github.com/grpc/grpc-java/blob/master/examples/src/ > main/java/io/grpc/examples/errorhandling/ErrorHandlingClient.java > > void run() throws Exception { > ... > public void sayHello(HelloRequest request, > StreamObserver<HelloReply> responseObserver) { > responseObserver.onError(Status.INTERNAL > .withDescription("Eggplant Xerxes Crybaby Overbite Narwhal"). > *asException()*); *//(1) specify it is a **StatusException** for the > caller.* > } > ... > } > > void blockingCall() { > ... > try { > stub.sayHello(HelloRequest.newBuilder().setName("Bart").build()); > } catch (*Exception e*) { *//(2): here I expected a StatusException > is threw, but actually it threw StatusRuntimeException.* > Status status = Status.fromThrowable(e); > ... > } > > > Regards, > > Benson > > -- > You received this message because you are subscribed to the Google Groups " > grpc.io" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/grpc-io/HK2PR04MB0866460C9A8D30D51ED8B5E2D1330%40HK2PR04MB0866. > apcprd04.prod.outlook.com > <https://groups.google.com/d/msgid/grpc-io/HK2PR04MB0866460C9A8D30D51ED8B5E2D1330%40HK2PR04MB0866.apcprd04.prod.outlook.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oPTWOvn1trhZ2v3U6XeemZWq002DBhrDxFg56qYxXo_0g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
