# ON ERROR GOTO Statement

#### Purpose:

To enable error trapping and specify the first line of the error-handling subroutine.

#### Syntax:

    ON ERROR GOTO line number

#### Comments:

Once error trapping has been enabled, all errors detected by GW-BASIC, including direct mode errors, (for example, syntax errors) cause GW-BASIC to branch to the line in the program which begins the specified error-handling subroutine.

GW-BASIC branches to the line specified by the ON ERROR statement until a RESUME statement is found.

If line number does not exist, an "Undefined line" error results.

To disable error trapping, execute the following statement:

    ON ERROR GOTO 0

Subsequent errors print an error message and halt execution.

An ON ERROR GOTO 0 statement in an error-trapping subroutine causes GW-BASIC to stop and print the error message for the error that caused the trap. It is recommended that all error-trapping subroutines execute an ON ERROR GOTO 0 if an error is encountered for which there is no recovery action.

If an error occurs during execution of an error-handling subroutine, the GW-BASIC error message is printed and execution terminated. Error trapping does not occur within the error-handling subroutine.

#### Examples:

    10 ON ERROR GOTO 1000
    .
    .
    .
    1000 A=ERR: B=ERL
    1010 PRINT A, B
    1020 RESUME NEXT

Line 1010 prints the type and location of the error on the screen (see the ERR and ERL variables).

Line 1020 causes program execution to continue with the line following the error.