How do I use RpcRaiseException() for good error handling?
There's RpcRais开发者_开发问答eException()
function in MS RPC runtime to indicate errors that occur during an RPC call either on the server side or in a pipe callback on the client side. The RPC_STATUS passed into RpcRaiseError()
is propagated to the site of the RPC call.
The problem is how do I choose the RPC_STATUS value?
Say in a pipe pull()
callback I read data from IStream*
and feed that data into the pipe. Now IStream::Read()
returns an HRESULT
indicating an error and I need to call RpcRaiseException()
to interrupt the call.
What value do I pass?
If you have an API which can fail, why not have the API return the failure code as the return value for the API?
If you DO want to use RpcRaiseException, the exception will be propogated as an exception to the client side so the exception code will show up as the RpcExceptionCode in the RpcExcept handler on the client side.
精彩评论