Exceptions

You can define exceptions in IDL, which are used to signal errors or other unusual circumstances that may occur during a remote method call. Exceptions are declared with a unique name, and an optional set of data attributes:

// IDL
exception identifier { <data member>; <data member>; ...};

Each data member on the exception type is simply a type specification followed by a unique identifier for the data member. The data is used to provide the caller with additional information about what went wrong during the remote method call.

Using our geometric examples from earlier, we might define an exception that is thrown when a MultiCoord with unexpected dimensions is passed into a method:

// IDL
exception BadDimension {
     short expected;
     short passed;
};

The server object raising one of these exceptions can set these data values, and the client making the request can read these values to interpret what went wrong.

Exceptions can be declared within any module or interface scope in your IDL file.

Standard Exceptions

In addition to user-defined exceptions, there are a set of standard exceptions defined within the CORBA module. These standard exceptions can be raised by any method, even though they aren’t listed explicitly in the method definition. These exceptions can be referenced in IDL using the CORBA:: scope (e.g., CORBA::BAD_PARAM). The standard CORBA exceptions are listed in Table 14-4. Every standard CORBA exception includes two data members: an unsigned long minor error code, ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.