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 GisException class. To catch and process specific exception types, nest catch statements as in the following example:

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

In some cases, underneath an FDO command, the GIS level throws a GisException. The FDO command then traps the GisException 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
  GisException* 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 GisPtr. The following example cleans up memory on error:

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

The catch and rethrow is unnecessary when GisPtr is used:

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