Skip to main content

ERR( ) Test Error Value

Formats

1.

Return ERR Position:

ERR(compare1,compare2,...[,ERR=stmtref])

2.

Return Extended Error Information:

ERR(keyword$ | "*")

2a.

Return Extended Error History:

ERR(keyword$, occurrence)

Where:

*

(asterisk) Lists the names of the returned values.

compare1,
compare2, ...

Comma-separated list of numeric values for comparison with the value of the internal ERR variable.

keyword$

Currently supported return values:

KeywordValue Returned
ERRError condition
RETOS error
OSERROS error message; i.e. MSG(-1)
PROGRAMPathname of program with error
STNOStatement number
OBJObject number
METHODMethod name invoked
LFALast file accessed
LFOLast file opened
LASTPATHLast pathname referenced
LASTKEYRecord key value, only valid for Error 11s
*Returns a list of all the possible ERR function keywords, comma-separated

occurrence

Error history occurrence where 1 is the last recorded error, 2 is the error before that, etc. Maximum value must be <= the value in the 'EH' system parameter. (added in PxPlus v10.10)

stmtref

Program line number or statement label to which to transfer control.

Description

The ERR( ) function can be used to determine the value of the internal ERR variable or receive additional information about the last un-trapped error.

Format 1

Return ERR Position

ERR(compare_1,compare_2,...compare_n[,ERR=stmtref])

Use this format to compare the value of the internal ERR variable with a list of possible external error values. If a match is found, the function returns an integer reporting the relative position of the value, which matches the value in the external ERR system variable. The function returns 0 (zero) if no match is found.

Example:

0040 on err(1,11,2) goto 1000,1010,1110,1020

Possible results:

ERR=1

Control transfers to line 1010.

ERR=11

Control transfers to line 1110.

ERR=2

Control transfers to line 1020.

ERR=0

No match. Control transfers to line 1000.

Format 2

Return Extended Error Information

ERR(keyword$ [,occurrence])

Where:

keyword$

Identifier of the error information you want returned.

occurrence

Option occurrence when accessing the error history, if enabled using the 'EH' system parameter. If omitted, the default error information from the last un-trapped exception is returned.

This format provides additional information for diagnosing un-trapped errors. The valid keywords vary from release to release. The currently supported keywords can be found by requesting ERR("*"), which will return a comma-delimited list of the keywords currently supplied. As of PxPlus 2018, this list contains:

KeywordDescription
ERRError code
ERXExtended error code (Not Currently Used)
RETOS error code
OSERROS error message
PROGRAMProgram that encountered error
ENTRYPOINTEntry point where execution started in program
STNOStatement/Line number where error occurred
OBJObject handle if error occurred in object
METHODEntry point if error occurred within an object method
LFALast file accessed
LFOLast file opened
LASTPATHPathname of last file opened
LASTKEYLast key used
MODULEInternal PxPlus module that trapped error
LINELine in module

The information returned by the default ERR( ) function is not affected by errors that are programmatically trapped using a SETERR or any of the ERR=/DOM=/BSY= options.

Example:

! Display ERR("xxx") return values
     error_handlerpgn+";ErrorHandler"
     print 4/0
     stop
!
!
ErrorHandler:
     print "Un-trapped error",err,":"
!
     for x$ from err("*") ! Process all entries in ERR information
          print x$,"=",err(x$)
     next x$
!
     exit err

See Also

ERR Last System-Detected Error Value
'EH' Error History Tracking
Error Codes and Messages