background image
Bionic Buffalo Tech Note #20: Quick Start Guide to Writing CORBA Client Applications 
Whether or not additional system object references will be required depends on the application itself,
and upon the mechanism which will be used to locate the server objects. For instance, if the server
objects are to be located using the name service, then an object reference for the name service object
will be needed. In C, this will be done using a call similar to
        name_service = ( CosNaming_NamingContext )
                CORBA_ORB_resolve_initial_references 
                ( orb, ( CORBA_ObjectId ) “NameService”, env ) ;
The 
orb object reference was acquired in the previous CORBA_ORB_init operation, and the env
pointer was acquired earlier as described. The 
resolve_initial_references() operation is
available in all language mappings, but of course its form depends on the rules of the mapping. 
Handle possible exceptions. At this point, it is appropriate to consider what happens when a call to an
object operation fails. In such cases, an exception will be raised, and the application must recognize
that this has happened and respond accordingly. 
The mechanisms for exception handling vary from one programming language to the next. Some
languages have built in or conventional procedures for using exceptions, and these may be used also
for CORBA exceptions. Other languages, such as C, have no such conventions, or the existing
mechanisms are inadequate, and the language mapping for each such language will define how that
language handles CORBA exceptions. 
CORBA exceptions have names and values. The name is defined by the IDL, and (depending on the
programming language) may appear to the application programmer as a string containing the
repository id of the exception definition. The value is an arbitrary data structure, which may be empty.
Exception values may be used to return almost any kind of information back to the application. The
data structure is defined in the IDL: although it may contain arbitrary information, it will always be the
same for a given exception name. 
In the C mapping, a member 
_major of the CORBA_Environment structure specifies whether or
not an exception has been raised. 
If 
env -> _major == CORBA_NO_EXCEPTION, then there has been no exception. 
If 
env -> _major == CORBA_SYSTEM_EXCEPTION, then a system exception has
been raised. The system exceptions and their corresponding data structures are defined in
the CORBA specification. An application must always be prepared to handle any system
exception. 
If 
env -> _major == CORBA_USER_EXCEPTION, then a user exception has been
raised. User exceptions are defined in the IDL for the operation being called. An
application should be prepared for any user exceptions defined in the IDL. 
Once a C application has recognized that an exception has been raised, it can use the function
CORBA_exception_id() to learn the name of the exception. Then one of the two routines
Page 7 of 11