Err Function

Returns the most recent error status.

Syntax
Err [ (taskNumber) ]

Parameters

taskNumber
Optional. Integer expression representing a task number from 0 to 32. “0” specifies the current task.

Return Values
Returns a numeric error code in integer form.

Description
Err allows the user to read the current error code. This along with the SPEL+ Error Handling capabilities allows the user to determine which error occurred and react accordingly. Err is used with OnErr.

To get the controller error, use SysErr function.

When the event “Error during Auto Mode” occurs, normal task and NoPause task in AUTO mode stop execution and end the task. If the target task has already ended when using this function for NoEmgAbort task or background task, “Error 2261” is occurred. Use OnErr to acquire information before the task ends.

See Also
Era, Erf$, Erl, ErrMsg$, EResume, Ert, OnErr, Return, SysErr

Err Function Example
The following example shows a simple utility program which checks whether points P0-P399 exist. If the point does not exist, then a message is printed on the screen to let the user know this point does not exist. The program uses the CX instruction to test each point for whether or not it has been defined. When a point is not defined control is transferred to the error handler and a message is printed on the screen to tell the user which point was undefined.

Function errtest
   Integer i, errnum
   Real x

   OnErr GoTo eHandle
   For i = 0 To 399
     x = CX(P(i))
   Next i
   Exit Function
'
'
'*********************************************
'* Error Handler                             *
'*********************************************
eHandle:
   errnum = Err
   ' Check if using undefined point
   If errnum = 78 Then
      Print "Point number P", i, " is undefined!"
   Else
      Print "ERROR: Error number ", errnum, " Occurred."
   EndIf
   EResume Next
Fend