Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Using Binding Handles and Making RPC Calls

Using Binding Handles and Making RPC Calls

A common mistake among RPC programmers is handling all exceptions. Many programmers structure their exception handles like the following:

    RpcTryExcept
        {
        RemoteSample();
        }
    RpcExcept(1)
        {
        log an error or do something else
        }
    RpcEndExcept

The problem with this handler is that it catches all errors, including errors in the client program. Catching errors in the client program makes debugging more difficult. The proper way to structure an exception handler is the following:


    RpcTryExcept
        {
        RemoteSample();
        }
    // Return "non-fatal" errors to clients.  Catching fatal errors
    // makes it harder to debug.
    RpcExcept( ( ( (RpcExceptionCode() != STATUS_ACCESS_VIOLATION) &&
                   (RpcExceptionCode() != STATUS_POSSIBLE_DEADLOCK) &&
                   (RpcExceptionCode() != STATUS_INSTRUCTION_MISALIGNMENT) &&
                   (RpcExceptionCode() != STATUS_DATATYPE_MISALIGNMENT) &&
                   (RpcExceptionCode() != STATUS_PRIVILEGED_INSTRUCTION) &&
                   (RpcExceptionCode() != STATUS_ILLEGAL_INSTRUCTION) &&
                   (RpcExceptionCode() != STATUS_BREAKPOINT) &&
                   (RpcExceptionCode() != STATUS_STACK_OVERFLOW) &&
                   (RpcExceptionCode() != STATUS_HANDLE_NOT_CLOSABLE) &&
                   (RpcExceptionCode() != STATUS_IN_PAGE_ERROR) &&
                   (RpcExceptionCode() != STATUS_ASSERTION_FAILURE) &&
                   (RpcExceptionCode() != STATUS_STACK_BUFFER_OVERRUN) &&
                   (RpcExceptionCode() != STATUS_GUARD_PAGE_VIOLATION)
                    )
                    ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) )
        {
        log an error or do something else
        }
    RpcEndExcept

This exception handler has the advantage of letting a certain range of errors through. These errors will never be returned by the server, because they indicate a client side problem.

Additionally, the use of the [strict_context_handle] and [type_strict_context_handle]attributes are recommended to ensure the RPC run time creates a context handle on one interface that can be passed as an argument only to methods of that interface. Doing so will prevent server failures that occur when context handles are opened and passed between different interfaces that exist within the same process.

Related topics

strict_context_handle
type_strict_context_handle

 

 

Community Additions

ADD
Show:
© 2015 Microsoft