CORBA client exception handling

The preferred coding practice for handling errors in C++ and Java code is to use exceptions, which is supported by using the standard try, catch, and throw logic of exception handling. Handling exceptions are a critical part of the client programming model. The exceptions that are thrown must be understood and handled appropriately by application developers.

In some cases, a server implementation object can encounter an error for which it might need to throw an exception to the client to give the client the opportunity to recover from the error.

This topic provides the following information about handling exceptions:

CORBA support, using appropriate exceptions

CORBA exceptions are used to communicate between server implementation objects and client applications. You must follow specific rules regarding which CORBA exceptions to use. The following abstract CORBA exception classes are defined:

CORBA::Exception
This is the abstract class that is the base of all of the CORBA exceptions. Because this class is an abstract, it is never thrown. However, it can be used in catch blocks to process all of the CORBA exceptions in one block.
CORBA::UserException
This is the abstract class for all of the CORBA user exceptions and is a subclass of CORBA::Exception. This class must be used as the base class of all user-defined exception classes. The contents of these classes have no special format. Methods that throw these classes must declare their usage in IDL using the raises clause.
CORBA::SystemException
This is the abstract class for all of the CORBA standard exceptions and is a subclass of CORBA::Exception. These exceptions can be thrown by any method regardless of the interface specification. Standard exceptions cannot be listed in raises expressions, therefore whether an interface throws a system exception is unknown. This means, be prepared to handle standard exceptions on all of the method calls. Each standard exception includes a minor code to provide more detailed information.

Any method can throw a standard exception, even if there are no exceptions declared in the raises clause of that method. Thus a method can throw an exception at any time.

Note: CORBA standard exceptions are a predefined list of exceptions that can be thrown from any method. CORBA has defined the class that provides this support as CORBA::System Exception. For more information about CORBA exceptions, see The Common Object Request Broker: Architecture and Specification.

CORBA support, catching exceptions

Client programs are required to handle exceptions because the default behavior for uncaught exceptions is to end the process. (If the client process ends unexpectedly, suspect an uncaught exception.)

A client program can handle exceptions within the catch clause of a try or catch block that encompasses remote method invocations or calls to ORB services. Typically, exception instances are actually instances of either the SystemException or UserException classes.

When deciding how or what exceptions to catch in a client application, consider the following general rules for exception handling:

Specific standard exceptions cannot be caught individually. If you need to handle individual standard exceptions, you can do so within a CORBA::SystemException catch block and use the id() method.

Consider the following simple client example:

try
{
   // Some real code goes here
   foo.boo();
}
// Catch and process specific User exceptions
...
// Catch any other User exceptions defined for the method in the
// `raises' clause
catch (CORBA::UserException &ue)
{
   // Process any other User exceptions. Use the id() method to
   // record or display useful information
   cout << "Caught a User Exception: " << ue.id() << endl;
}
// Catch any System exceptions
catch (CORBA::SystemException &se)
{
   // Process any System exceptions. Use the id() and minor()
   // methods to record or display useful information
   cout << "Caught a System Exception: " << ue.id() << ": " << 
        ue.minor() << endl;
}
catch (...)
{
   // Process any other exceptions. This would catch any other C++
   // exceptions and should probably never occur
   cout << "Caught an unknown Exception" << endl;
}


Related tasks
Developing a CORBA C++ client
Related reference
CORBA module: Exception Class
CORBA module: UserException Class
ORB::list_initial_services
CORBA module: SystemException Class



Searchable topic ID:   ccor_ipgmce
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/concepts/ccor_ipgmce.html

Library | Support | Terms of Use | Feedback