PreviousNext

Exceptions

Exceptions report either RPC errors or errors in application code. Exceptions have the following characteristics:

· You do not have to adjust procedure declarations between local and distributed code.

· You can distribute existing interfaces without changing code.

· You do not have to check for failures. This results in more robust code because errors are reported even if they are not checked.

· Your code is more efficient when there is no recovery coded for failures.

· You can use a simpler coding style.

· Exceptions work well for coarse-grained exception handling.

· If your application does not contain any exception handlers and the application thread gets an error, the application thread is terminated and a system-dependent error message from the threads package is printed.

Note: RPC exceptions are equivalent to RPC status codes. To identify the status code that corresponds to a given exception, replace the _x_ string of the exception with the string _s_. For example, the exception rpc_x_comm_failure is equivalent to the status code rpc_s_comm_failure. The RPC exceptions are defined in the dce/rpcexc.h header file, and the equivalent status codes are described in the OSF DCE Problem Determination Guide.

The set of exceptions that can always be returned from the server to the client (such as the rpc_x_invalid_tag exception) are referred to as system exceptions. These exceptions are defined in dce/rpcexec.h and dce/exec_handling.h.

An interface definition can also specify a set of user-defined exceptions that the interface's operations can return to the client. You can declare user-defined exceptions in an interface definition by using the exceptions interface attribute, which is described in Interface Definition Language.

If a user-defined exception in the implementation of a server operation occurs during server execution, the server terminates the operation and propagates the exception to the client in a manner similar to the way system exceptions are propagated. If a server implementation of an operation raises an exception that is neither a system exception nor a user-defined exception, the exception returned to the client is rpc_x_unknown_remote_fault.

By default, the IDL compiler defines and initializes all exceptions under a "once block'' in the generated stubs. If you want to share exception names in multiple interfaces or you desire greater control over how these exceptions are defined and initialized, you can use the ACF extern_exceptions attribute to disable the automated mechanism that the IDL compiler uses to define and initialize exceptions. See Attribute Configuration Language for more information on the extern_exceptions attribute.

Because exceptions are associated with operation implementation, they are not imported into other interfaces by way of the import declaration. For more information about using exceptions to handle errors, see Part 2 of this guide.