Exceptions

The AS/400 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.

Each exception contains three pieces of information:

  • Error type - The exception object that is thrown indicates the type of error that occurred. Errors of the same type are grouped together in an exception class. See the list of exceptions for more information about error types.

  • Error details - The exception contains a return code to further identify the cause of the error that occurred. The return code values are constants within the exception class.

  • Error text - The exception contains a text string that describes the error that occurred. The string is translated in the locale of the client Java Virtual Machine (JVM).

Note: The AS400JDBCException class follows JDBC standards and not all information is listed here. For more information about AS400JDBCException, see the JDBC Database Access API web page.

The following example shows how to catch a thrown exception, retrieve the return code, and display the exception text:

                       // ... all the setup work to delete
                       // a file on the AS/400 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 you
                       // want to track

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

See exceptions inheritance structure for more information about exceptions.


[ Legal | AS/400 Glossary ]