ERR and ERRCLEAR system variables

Purpose

Return the error code of the most recent PowerBASIC run-time error.

Syntax

y = ERR

ERR = ErrNum

y = ERRCLEAR

ERRCLEAR

Remarks

ERR and ERRCLEAR return the error code of the most recent run-time error in the current Sub, Function, Method, or Property.  This number can be tested after any critical operation, so that appropriate error-handling code can be executed.

You can also assign a value to ERR.  This is similar to executing an ERROR statement, except no error is generated.  Instead, subsequent tests of ERR and ERRCLEAR reflect ErrNum.  To explicitly raise an exception in a TRY/END TRY block, use the ERROR statement.

ERRCLEAR returns the error code of the most recent run-time error.  In addition, it resets PowerBASIC's internal error code variable ERR to zero after you reference it.  This ensures that the next time you test ERR or ERRCLEAR, you are guaranteed to get a zero, unless there has actually been an error since the last ERRCLEAR.  ERR, on the other hand, does not reset the internal error code.  It retains its value until it is changed, either by a run-time error or explicitly by your code (using the ERR= or ERROR =statements).

ERRCLEAR can also be used as a statement to reset ERR to zero.  ERRCLEAR, when used as a statement, is equivalent to ERR = 0.

IMPORTANT: Be sure to study the Errors and Error Trapping.

Restrictions

Valid run-time error values are in the range 1 through 255.  Attempting to set an error value (with the ERROR statement) outside of that range will convert the value to a run-time Error 5 ("Illegal function call").

See also

ERROR, ERROR$, Error OverviewError TrappingON ERROR, Run-time Errors

Example

y = ERR        ' sets y = ERR

ERR = 6        ' sets ERR to 6

y = ERRCLEAR   ' sets y = ERR and ERR = 0

ERRCLEAR       ' sets ERR = 0