Exception handling in gRPC

Kevin picture Kevin · Aug 7, 2016 · Viewed 9.3k times · Source

I have a server written in Java and client written in PHP. How can client catch exception from server if anything goes wrong? I can't find anything about exception handling in gRPC documentation.

Thank you!

Answer

Eric Anderson picture Eric Anderson · Aug 8, 2016

For handled exceptions, call responseObserver.onError(). If you pass in a StatusRuntimeException or StatusException (generally created via status.asRuntimeException()) the status code and description will be communicated to the client. Unhandled exceptions within a callback will cancel the RPC and will continue propagating the exception (generally leading in an UncaughtExceptionHandler being called for the executor).