Error Handling (V26)

ON ERROR GOTO

Syntax: ON ERROR GOTO label

Redirects runtime errors to a label. Use ERR and ERL to inspect the error.

ON ERROR GOTO failed
' ... code that may error ...
EXIT FUNCTION
failed:
    PRINT "Error "; ERR; " at line "; ERL
    ERRCLEAR
    RESUME NEXT

ON ERROR RESUME NEXT

Syntax: ON ERROR RESUME NEXT

Ignores errors and continues execution at the next statement.

ON ERROR RESUME NEXT
x = 1 / 0     ' Division by zero ignored
PRINT "continues"

ON ERROR GOTO 0

Syntax: ON ERROR GOTO 0

Disables error trapping. Errors terminate the program.

ERR

Syntax: ERR

Returns the last runtime error number.

ERL

Syntax: ERL

Returns the line number of the last runtime error.

ERRCLEAR

Syntax: ERRCLEAR

Clears the current error state. Sets ERR to zero and clears the error flag.

ERROR n

Syntax: ERROR n

Triggers a runtime error with code n. If no error handler is active, the program terminates.

ERROR 9    ' Trigger subscript error

RESUME / RESUME NEXT

Syntax: RESUME | RESUME NEXT

RESUME retries the statement that caused the error. RESUME NEXT continues after it. Must be called from within an error handler.

failed:
    PRINT "Error handled"
    ERRCLEAR
    RESUME NEXT