KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Enhancing an error handler method in 4D v12
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: August 18, 2010

In 4D v12 developers can now know precisely where an error occurred. With an error hander installed, using ON ERR CALL, two new system variables Error method and Error line are available in addition to the traditional system variable Error.

The code snippet below demonstrates how to enhance an error handling method in 4D v12 to provide the method name and line number of an error that just occurred.

If (Error#0)
    C_LONGINT($Error_L;$ErrorLine_L)
    C_TEXT($ErrorMethod_T;$Msg_T)

      // Copy the 4D system variables in my own
      //
    $ErrorCode_L:=Error
    $ErrorMethod_T:=Error method
    $ErrorLine_L:=Error Line

    Error:=0
    Error method:=""
    Error Line:=0

    $Msg_T:="Error: "+String($ErrorCode_L)+"\r"
    $Msg_T:=$Msg_T+"Error Method: "+$ErrorMethod_T+"\r"
    $Msg_T:=$Msg_T+"Error Line: "+String($ErrorLine_L)+"\r\r"
    $Msg_T:=$Msg_T+"Please report this error information to the developer ASAP."
    ALERT($Msg_T)
End if

Remember, these variables are only available within the error handling method installed with ON ERR CALL.