System Functions

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:

Keyword

Value Returned

ERR

Error condition

RET

OS error

OSERR

OS error message; i.e. MSG(-1)

PROGRAM

Pathname of program with error

STNO

Statement number

OBJ

Object number

METHOD

Method name invoked

LFA

Last file accessed

LFO

Last file opened

LASTPATH

Last pathname referenced

LASTKEY

Record 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:

Keyword

Description

ERR

Error code

ERX

Extended error code (Not Currently Used)

RET

OS error code

OSERR

OS error message

PROGRAM

Program that encountered error

ENTRYPOINT

Entry point where execution started in program

STNO

Statement/Line number where error occurred

OBJ

Object handle if error occurred in object

METHOD

Entry point if error occurred within an object method

LFA

Last file accessed

LFO

Last file opened

LASTPATH

Pathname of last file opened

LASTKEY

Last key used

MODULE

Internal PxPlus module that trapped error

LINE

Line 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