Exceptions

The IBM® Toolbox for Java™ access classes throw exceptions when device errors, physical limitations, programming errors, or user input errors occur. The exception classes are based upon the type of error that occurs instead of the location where the error originates.

Most exceptions contain the following information:

Example: Catching a thrown exception

The following example shows how to catch a thrown exception, retrieve the return code, and display the exception text:
Note: Read the Code example disclaimer for important legal information.
     // All the setup work to delete a file on the server through the
     // IFSFile class is done. Now try deleting the file.
     try
     {
        aFile.delete();

     }

     // The delete failed.
     catch (ExtendedIOException e)
     {
        // Display the translated string containing the reason that the
        // delete failed.
        System.out.println(e);

        // Get the return code out of the exception and display additional
        // information based on the return code.
        int rc = e.getReturnCode()

        switch (rc)
        {
           case ExtendedIOException.FILE_IN_USE:
              System.out.println("Delete failed, file is in use "):
              break;

           case ExtendedIOException.PATH_NOT_FOUND:
              System.out.println("Delete failed, path not found ");
              break;

           // For every specific error that you want to track...

           default:
              System.out.println("Delete failed, rc = ");
              System.out.println(rc);
        }
     }