Serializing component instance references  Deploying and running Java clients

Chapter 12: Creating CORBA Java Clients

Handling exceptions

The client-side ORB throws two kinds of exceptions:

CORBA system exceptions

The CORBA specification defines the list of standard system exceptions. In Java, all CORBA system exceptions extend org.omg.CORBA.SystemException. System exceptions are unchecked exceptions (they extend java.lang.RuntimeException). The Java compiler does not require that you catch CORBA system exceptions. However, some exceptions can occur in a well-behaved program. For example, the Session.loookup call throws a NO_PERMISSION exception when you request a component instance and the user lacks permission to instantiate that component. You may want to trap the exceptions shown in the code fragment below:

    // invoke method(s)
catch (org.omg.CORBA.COMM_FAILURE cf)
    // If this occurs when instantiating a Manager
    // instance, the server is likely down or has run 
    // out of connections. You can retry the connection
    // if desired.
    // If this occurs after a method call, you 
    // can retry the call (or the transaction call 
    // sequence for a stateful component).
    // A component on the server aborted the EAServer 
    // transaction, or the transaction timed out.
    // Retry the method call(s) if desired.
catch (org.omg.CORBA.OBJECT_NOT_EXIST one)
    // Possibly try to create another instance. Check 
    // that the package and component are installed 
    // on the server.
    // Received when trying to instantiate a component
    // that does not exist. Also received when invoking
    // a method if the object reference has expired 
    // (this can happen if the component is stateful
    // and is configured with a finite Instance Timeout
    // property). Create another instance if desired.
catch (org.omg.CORBA.NO_PERMISSSION np)
    // Tell the user they are not authorized
catch (org.omg.CORBA.SystemException se)
    // Catch-all clause for any CORBA system exception
    // that was not explicitly caught above. 
    // Report the error but don’t bother retrying.

NoteNot all of the possible system exceptions are shown in the example. See CORBA/IIOP 2.3 Specification for a list of all the possible exceptions.

User-defined exceptions

User-defined exceptions are defined in the component’s IDL definition. For example, you might define OverdrawnException to be thrown by methods that withdraw money from a bank account. In Java, all user-defined exceptions extend org.omg.CORBA.UserException.

In Java, IDL user-defined exceptions are checked exceptions; if the IDL definition of a method contains a raises clause, the equivalent Java stub method will have a throws clause that lists the equivalent Java exceptions. For example, consider the IDL definition below:

module MyModule {
  exception MyException
    string reason;

  interface MyIntf {
    boolean throwException 
    ( in boolean yes_no )
    raises (MyException);

The equivalent Java throwException method is:

boolean throwException (boolean yes_no) 
   throws MyModule.MyException;

Copyright © 2005. Sybase Inc. All rights reserved. Deploying and running Java clients