DB Access Class Library for COBOL V1.0 API Reference - Microsoft(R) Windows(R) - - Microsoft(R) Windows NT(R) - - Microsoft(R) Windows(R) 2000 -
Contents Index PreviousNext

UpChapter 4 Examples of Using the DB Access Class Library

4.4 Procedure Pertaining to Error Information (Exception Object)


When an error occurs while the DB access class library is used, detailed information about the error, such as error code, message text, and SQLSTATE, can be collected by handling an object of the FJDB-ERROR class as an exception object.

A procedure pertaining to the exception object must appear in the declaratives portion of the procedure part of the program that uses the DB access class library.
A procedure pertaining to the exception object coded in the program that uses the DB access class library would launch an error handling routine when an error occurs during the DB access class library, generating information about the error.

A sample coding of the error handling routine is shown below.

In this example, control returns to ERR-PROC as the GO TO statement following the error handling routine is executed.

Without this GO TO statement, control would return to the line just after the line on which the error was encountered.


  1. Define the class.

    Define the class to use in the repository paragraph of the CONFIGURATION SECTION.

     CONFIGURATION SECTION
     REPOSITORY.
         CLASS FJDB-ERROR.
  2. Define variables.

    Define the variables to use in the program.

     WORKING-STORAGE SECTION
    *Define the object variable
     01 ERROR-A USAGE OBJECT REFERENCE FJDB-ERROR.
    *Define the variables for storing error information
     01 ERROR-COUNT    PIC S9(9) COMP-5.
     01 ERROR-MESSAGE  PIC X(200).
     01 SQLSTATE       PIC X(5).
     01 SQLSTATE-SIZE  PIC S9(9) COMP-5.
     01 MESSAGE-SIZE   PIC S9(9) COMP-5.
    *Define the return value variable
     01 RET-CODE       PIC S9(9) COMP-5.
  3. Write a routine for handling the exception object in the declaratives portion of the procedure part of the program.

    Write an appropriate error handling response.
    This is always required in a program.

     DECLARATIVES.
     ERR SECTION.
         USE AFTER EXCEPTION FJDB-ERROR.
         INVOKE EXCEPTION-OBJECT "GET-COUNT" RETURNING ERROR-COUNT
         PERFORM ERROR-COUNT TIMES
             INVOKE EXCEPTION-OBJECT "GET-SQLSTATE" 
                                          USING SQLSTATE SQLSTATE-SIZE
                                          RETURNING RET-CODE
             INVOKE EXCEPTION-OBJECT "GET-MESSAGE"
                                          USING ERROR-MESSAGE MESSAGE-SIZE
                                          RETURNING RET-CODE
             DISPLAY "SQLSTATE=" SQLSTATE
             DISPLAY "MESSAGE=" ERROR-MESSAGE
             INVOKE EXCEPTION-OBJECT "GET-NEXT" RETURNING RET-CODE
         END-PERFORM.
         GO TO ERR-PROC.
     END DECLARATIVES.
          :
          :
     ERR-PROC.
          :
          :
         STOP RUN.

Contents Index PreviousNext

All Rights Reserved, Copyright (C) Alchemy Solutions Inc. 1998-2000