6. Embedded QUEL for BASIC : Runtime Error Processing : Programming for Error Message Output
 
Share this page                  
Programming for Error Message Output
By default, all Ingres and forms system errors are returned to the EQUEL program, and default error messages are printed on the standard output device. As discussed in the QUEL Reference Guide and the Forms-based Application Development Tools User Guide, you can also detect the occurrences of errors by means of the program using the inquire_ingres and inquire_frs statements. (Use the latter for checking errors after forms statements—see the examples in the Forms-based Application Development Tools User Guide. Use inquire_ingres for all other EQUEL statements.)
This section discusses an additional technique that enables your program not only to detect the occurrences of errors, but also to suppress the printing of default Ingres error messages if you choose. The inquire statements detect errors but do not suppress the default messages.
This alternate technique entails creating an error-handling function in your program and passing its address to the Ingres runtime routines. Then Ingres will automatically invoke your error handler whenever an Ingres or a forms-system error occurs. Your program error handler must be declared as follows:
function integer funcname (err_no)
...
end function
This function must be passed to the EQUEL routine IIseterr( ) for runtime bookkeeping using the statement:
call IIseterr(funcname)
This forces all runtime Ingres errors through your function, passing the error number as an argument. If you choose to handle the error locally and suppress Ingres error message printing, the function should return 0; otherwise the function should return the Ingres error number received. The error-handling function must return a long integer. If your default integer size is less than 4 bytes, you must declare the function to be a long function.
Avoid issuing any EQUEL statements in a user-written error handler defined to IIseterr, except for informative messages, such as message, prompt, sleep and clear screen, and messages that close down an application, such as endforms and exit.
The example below demonstrates a typical use of an error function to warn users of access to protected tables. This example passes through all other errors for default treatment.
1    ##     declare ingres
          external integer Err_Trap

     ##     Ingres personnel
          call IIseterr(Err_Trap)

          ...
     ##     exit
          end

2          function integer Err_Trap(integer ingerr)

               ! Error number for protected tables
               declare integer constant TBLPROT = 5003%

           if (ingerr = TBLPROT) then
               print 'You are not authorized for this operation'
               Err_Trap = 0%           ! Do not print messages
            else
                    Err_Trap = ingerr     ! Ingres will print error
           end if
       end function