Exceptions from the ODK API library

When you write code for an ODA, you can include Java try and catch statements to handle specific exceptions thrown by the methods of the ODK API. The reference description for most ODK API methods has a section entitled Exceptions, which lists the exceptions thrown by that method.

Figure 76 shows a code fragment from sample Roman Army ODA (in the ArmyAgent4 class) that catches the exceptions that the getClientFile() method throws.

Figure 76. Catching exceptions from getClientFile()

try
    {
    remotefile = ODKUtility.getODKUtility().getClientFile(filePath, this);
    }
 
catch (IOException ex)            //file was not found
    {
     return null;
    }
 
//agent doesn't implement IGeneratesBinFiles, so "getClientFile" failed.
 catch (UnsupportedContentException ex)   
    {                              //We'll return a random Son instance for now.
     return new Son("X" + ("" + new Date().hashCode()).substring(1), 
        new Date().hashCode() % 10  + 2);
    }
 

When an ODK API method throws an exception, it does not usually provide message and status information in the exception object. However, you can choose to fill the exception object with a message as needed.

Copyright IBM Corp. 1997, 2004