How error traps work

In PowerBASIC, error codes - returned by the ERR or ERRCLEAR functions - and error traps are local to each Sub, Function, Method, or Property. An error trap will only trap errors that occur within the procedure where it is defined.

PowerBASIC uses the following steps to determine what to do when a run-time error occurs:

· | Does an error trap exist? If so, PowerBASIC uses it.

· | If no error trap exists, PowerBASIC places an error code in the ERR and ERRCLEAR system variables and continues execution.

Consider the following:

SUB Proc1

ON ERROR GOTO ErrorTrap

' some code goes in here

CALL Proc2

' some more code goes in here

Proc1Resume:

EXIT SUB

ErrorTrap:

' Error-handling code goes in here

RESUME Proc1Resume

END SUB

See Also

Error Overview

Error Trapping

Setting an error trap

Writing an error handler

Exiting an error handler

Error Trapping Summary