StatusRuntimeException

StatusRuntimeException

本文介绍了gRPC中的异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Java编写的服务器和一个用PHP编写的客户端.如果出现任何问题,客户端如何从服务器捕获异常?在gRPC文档中找不到任何有关异常处理的信息.

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.

谢谢!

推荐答案

对于已处理的异常,请调用responseObserver.onError().如果传入StatusRuntimeExceptionStatusException(通常是通过status.asRuntimeException()创建的),则状态代码和描述将传达给客户端.回调中未处理的异常将取消RPC,并将继续传播异常(通常导致为执行程序调用UncaughtExceptionHandler).

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).

这篇关于gRPC中的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 14:20