![]() |
It is a requirement to handle exceptions in client programs. Remember that any method might throw a standard exception, therefore an exception can be thrown by these methods at any time - even if there are no exceptions declared in the raises clause of that method. The default behavior for uncaught exceptions is to end that process. If this happens, suspect an uncaught exception first. The exact style of how or what exceptions are caught depends on what the client application does for error recovery but there are some good general rules to follow:
- Perform as specific error recovery as makes sense. By proper structuring of catch clauses specific error recovery can be done.
- Check for most specific exceptions first, most general exceptions last.
- Make use of information that is available in the exception. All CORBA exceptions support the .id() method that returns the exception identifier. System exceptions also provide .minor() and .completed() methods which return the minor code and completion status respectively.
Here is a simple client code example:
try { // Some real code goes here foo.boo(); } // Catch any specific User exceptions defined for the method in the // `raises' clause catch (IManagedClient::INoObjectWKey nowk) { // Process the error, more specific recovery could be made here // because the specific error is known } // Catch and process any other 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 defined for the method in the // `raises' clause 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; }Specific standard exceptions cannot be caught individually. If processing individual standard exceptions is required it can be done within the CORBA::SystemException catch block and using the .id() method.
Related reference... | |
CORBA C++ bindings | |
Parent: CORBA exceptions | |
Throwing CORBA exceptions | |