![]() |
The preferred coding practice for handling errors in C++ and Java is by using exceptions, which is supported by using the standard try and throw logic of exception handling. Handling exceptions is 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:
Any method can throw a standard exception, even if there are no exceptions declared in the raises clause of that method, so a method can throw an exception at any time.
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/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; }