Skip to content

Error_Report - cBaseErrorHandler

Sent if you have redirected your errors to another object, and this new error object wishes to use the services of the standard error handler

Type: Event

Parameters

Parameter Type Description
iErrNum Integer The error number
iErrLine Integer The error line number
sErrText String The additional error text that would have been passed with the error command (e.g., Error 300 "This is an error")

Syntax

Procedure Error_Report Integer iErrNum Integer iErrLine String sErrText

Description

The Error_report message may be sent if you have redirected your errors to another object, and this new error object wishes to use the services of the standard error handler. When this message is sent the following occurs:

  1. The procedure makes sure that it is not already processing an error. If it is, it exits. If it is not, it sets error_processing_state to true to indicate that an error is in process.

  2. If the error number is ignored (not trapped), the error process is passed on to the standard internal error handler (which does not report the error).

  3. An error description is created by appending the standard DataFlex error text for the passed error number (if text exists) with the error message text passed (if text exists).

  4. The handler checks to see if the Global Integer ghoErrorSource is non-zero. If it is, it will send the message get extended_error_message to ghoErrorSource. This function will be return additional error text. This provides an advanced method for generating additional error text. The return string may be multi-line text-each line should be separated with a \n end-of-line symbol.

  5. The error and all error text is displayed in an message box via the Message_Box function call. If the error is considered critical (calls private Is_Critcal function), the icon displayed is MB_IconHand, otherwise MB_IconExclamation is shown.

  6. If the error is critical, the program is halted

  7. The global integer ghoErrorSource is reset to 0.

  8. The property error_processing_state is reset to false.

The following sample shows how an error may redirected to a custom error handler and how this custom error handler will use the standard error handler.

Object Process is a SomeClass

    Property Integer OldErrorId 0
    Property Integer Error_Processing_State False // required

    Procedure Run_Process
        integer hID

        Set OldErrorId 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 OldErrorId to hId
        Move hId to Error_Object_Id              // restore original error object
    End_Procedure

    Procedure Error_Report Integer iErrNum Integer iErrLine String sErrText
        Integer hId
        // Always check that we are not already in an error         
        If (Error_Processing_State(Self)) ;
            Procedure_Return
        Set Error_Processing_State to true // we are now within an error
        : perform custom error handling
        // Now direct the error to the standard error handler
        Get OldErrorId to hId
        Send Error_Report of hId iErrNum iErrLine sErrText

        Set Error_Processing_State to false // we are no longer within an error
    End_Procedure

End_Object

In the following sample, ghoErrorSource and extended_error_message are used to provide additional error text to the error handler. This is an advanced technique and must be very carefully applied. This technique is used to provide additional information in errors generated by data dictionaries.

Procedure Error_Report Integer iErrNum Integer iErrLine String sErrText
    Integer hId

    If (Error_Processing_State(Self)) ;
        Procedure_Return
    Set Error_Processing_State to True
    : perform custom error handling
    Get OldErrorId to hId
    // By setting this value, we expect that standard error handler will now
    // send the message Get Extended_error to this object. We will create this
    // function in this object.

    Move Self to ghoErrorSource 
    Send Error_Report of hId iErrNum iErrLine sErrtext
    Move 0 to ghoErrorSource 
    Set Error_Processing_State to False
End_Procedure

Function Extended_Error_Message returns String
    string sText

    // Note that "\n" will break the line when displayed
    Move "This is a serious error.\nDo not ignore this." to sText

    Function_Return sText
End_Function
Col 1 Col 2
Note: The previous versions of DataFlex only required two parameters for this message - the error number and line number were packed in a single folded integer. Three parameters are now required. If you have old code that uses this, it must be changed.