Click to Rate and Give Feedback
MSDN
MSDN Library
Networking
Network Protocols
Overviews
 Exception Handling
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Exception Handling

RPC uses the same approach to exception handling as the Windows API.

The RpcTryFinally / RpcFinally / RpcEndFinally structure is equivalent to the Windows try-finally statement. The RPC exception construct RpcTryExcept / RpcExcept / RpcEndExcept is equivalent to the Windows try-except statement.

When you use the RPC exception handlers, your client-side source code is portable. The different RPC header files provided for each platform resolve the RpcTry and RpcExcept structures for each platform. In the Windows environment, these macros map directly to the Windows try-finally and try-except statements. In other environments, these macros map to other platform-specific implementations of exception handlers.

Potential exceptions raised by these structures include the set of error codes returned by the RPC functions with the prefixes RPC_S_ and RPC_X and the set of exceptions returned by Windows. For details, see RPC Return Values.

Exceptions that occur in the server application, server stub, and server run-time library (above the transport layer) are propagated to the client. No exceptions are propagated from the server-transport level. The recommended method for a server routine to return errors to the RPC run time is to throw an exception. A server routine can use whatever methods is appropriate for communicating errors between server routines, but if it encounters an error that prevents it from executing the remote procedure, it should raise an exception after cleaning up and before returning to the RPC run time, rather than returning a value to RPC that only the server routine recognizes as an error.

The following figure shows how exceptions are returned from the server to the client.

 

exceptions are returned from the server to the client through the respective RPC Runtime of each component

 

 

The RPC exception handlers differ slightly from the Open Software Foundation-Distributed Computing Environment (OSF-DCE) exception-handling macros TRY, FINALLY, and CATCH. Various vendors provide include files that map the OSF-DCE RPC functions to the Microsoft RPC functions, including TRY, CATCH, CATCH_ALL, and ENDTRY. These header files also map the RPC_S_* error codes onto the OSF-DCE exception counterparts, rpc_s_*, and map RPC_X_* error codes to rpc_x_*. For OSF-DCE portability, use these include files. For more information about the RPC exception handlers, see RpcExcept and RpcFinally. For more information about the Windows exception handlers, see Structured Exception Handling.

Send comments about this topic to Microsoft

Build date: 5/28/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker