Section G.8. Exceptions


G.8. 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.

G.8.1. Standard Exceptions

In addition to user-defined exceptions, a set of standard exceptions is 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 G-4. Every standard CORBA exception includes two data members: an unsigned long minor error code, which can further specify the type of error that occurred, and a completion_status enum that can be one of COMPLETED_YES, COMPLETED_NO, and COMPLETED_MAYBE. These status values indicate that before the exception was raised, the method was either completed, was never initiated, or is in an unknown state, respectively.

Table G-4. Standard CORBA exceptions

Exception name

Meaning

BAD_CONTEXT

Failure while accessing the context object.

BAD_INV_ORDER

Some methods were called out of their expected order.

BAD_OPERATION

An invalid method was called.

BAD_PARAM

An invalid argument was passed into a method.

BAD_TYPECODE

A bad type code was used.

CODESET_INCOMPATIBLE

The underlying protocol code sets between the client and the server are incompatible.

COMM_FAILURE

A communication failure occurred.

DATA_CONVERSION

Error while converting data.

FREE_MEM

Failed to free some memory.

IMP_LIMIT

Some implementation limit was exceeded.

INITIALIZE

The ORB initialization failed.

INTERNAL

An internal ORB error occurred.

INTF_REPOS

Error attempting to access interface repository.

INV_FLAG

An invalid flag was given.

INV_IDENT

Invalid identifier syntax was encountered.

INV_OBJREF

An invalid object reference was encountered.

INV_POLICY

An operation couldn't be performed because of incompatible security policy settings.

INVALID_TRANSACTION

An invalid transaction was used.

MARSHAL

An error occurred while marshaling method arguments or results.

NO_IMPLEMENT

The implementation for the method is not available.

NO_MEMORY

Failed to allocate dynamic memory needed to execute the request.

NO_PERMISSION

Not allowed to execute the method.

NO_RESOURCES

There were insufficient resources for the request.

NO_RESPONSE

No response received for request.

OBJ_ADAPTER

The object adapter encountered an error.

OBJECT_NOT_EXIST

The referenced object doesn't exist on the server.

PERSIST_STORE

An error occurred while accessing persistent storage.

TRANSACTION_REQUIRED

An operation requiring a transaction was called without one.

TRANSACTION_ROLLEDBACK

A transactional operation didn't complete because its transaction was rolled back.

TRANSIENT

A transient error occurred, but the method can be tried again.

UNKNOWN

An error occurred that the ORB couldn't interpret.


G.8.2. Mapping Exceptions to Java

User-defined exceptions are mapped to public final Java classes that extend org.omg.CORBA.UserException, which is derived directly from java.lang.Exception. Otherwise, the exception is mapped to Java in the same way as structs, as described previously. Each data member is mapped to a public data member of the corresponding type, and a set of constructors is defined for the exception class.



Java Enterprise in a Nutshell
Java Enterprise in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596101422
EAN: 2147483647
Year: 2004
Pages: 269

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net