Exception Handling

FDO API

 
Exception Handling
 
 
 

In the FDO API, FdoCommandException class is the exception type thrown from classes in the Commands package, and FdoConnectionException class is the exception type thrown from classes in the Connections package. Both of these exception types derive from a language-level exception class that is environment-specific.

All exceptions are derived from the FdoException class. To catch and process specific exception types, nest catch statements as in the following example:

try {
... code
}
  catch (FdoCommandException *ex){
    .. process message
    }
  catch (FdoException *ex){
    .. process message
    }

In some cases, underneath an FDO command, the FDO level throws an FdoException. The FDO command then traps the FdoException and wraps it in an FdoCommandException (or FdoSchemaException for a schema command). In this case, several messages are returned by one exception. The following example shows how to process multiple messages from one exception:

catch ( FdoSchemaException* ex )  {
  // Loop through all the schema messages
  FdoException* currE = ex;
  while ( currE ) {
    CW2A msg(currE->GetExceptionMessage());
    acutPrintf ("FdoConnectionException: %s\n", msg);
    currE = currE->GetCause();

An application function may need to catch and then re-throw exceptions in order to clean up memory. However, the need to do this can be eliminated by using FdoPtr. The following example cleans up memory on error:

FdoFeatureClass* pBase = NULL; 
try { 
pBase = myClass->GetBaseClass(); 
... 
} 
catch (...) { 
FDO_SAFE_RELEASE(pBase); 
throw; 
} 
// Must release reference added by GetBaseClass when done. 
FDO_SAFE_RELEASE(pBase); 

The catch and rethrow is unnecessary when FdoPtr is used:

FdoPtr<FdoFeatureClass> pBase = myClass->GetBaseClass(); 
...