Skip to content

Handling Errors in Batch Processes

First, we must understand how the error handler works in DataFlex. A global Integer named error_object_id determines which object should receive errors. Anytime an error occurs, the message error_report is sent to the object identified by this global Integer. When the standard error package, Dferror.Pkg (which is included in DfAllEnt.pkg), is used, a global error object is created, and its object ID is moved to error_object_id. Anytime an error occurs, the message error_report is sent to the error object. You can turn any object into an error-handling object by creating an error_report procedure and moving its object ID to error_report_object.

Normally, when a DataFlex error is directed to the global error object, the object will display an interactive error message and allow users to proceed (unless, of course, the error is fatal). You usually need more control of errors during a batch process. The best way to do this is to redirect the errors to an object that handles batch errors in a customized fashion. The easiest way to do this is to direct the errors to the object that is running the batch process. This is what the report object does automatically. Not only does this allow handling of the status panel (which must be removed if the error is to be displayed), but it also allows users to decide how to handle the error.

This redirection could be done in the following fashion:

Object Process is a SomeClass
    Property Integer piOldErrorId

    Procedure Run_Batch_Process
        Integer iId
        Set piOldErrorId to Error_Object_Id  // remember old error object
        Move Self to Error_Object_Id          // make Self the error object

        Repeat
            // run the batch process
        Until (done)

        Get piOldErrorId to iId
        Move iId to Error_Object_Id            // restore original error object
    End_Procedure

    Procedure Error_Report Integer iErrorNumber Integer iErrorLine String sErrorText
        // handle custom error here
    End_Procedure
End_Object

Here would be one way to handle errors with a status panel:

Procedure Error_Report Integer iErrorNumber Integer iErrorLine String sErrorText
    Integer iId
    Send Stop_StatusPanel of ghoStatusPanel  // remove panel for error

    // direct error to standard error handler
    Get piOldErrorId to iId
    Send Error_Report of iId iErrorNumber iErrorLine sErrorText

    Send Start_StatusPanel of ghoStatusPanel // put panel back
End_Procedure

See Also