To enable error trapping and specify the first line of the error-handling subroutine.
ON ERROR GOTO line number
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.
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 ERRERL variables).
Line 1020 causes program execution to continue with the line following the error.
All Frank Sinatra recordings, All Beatles albums, All solo albums from John Lennon, Paul McCartney, George Harrison and Ringo Starr, All Beatles songs, List of Platinum selling albums, Database with hits from 1950 to 1999.
Sought after DLL files, Nutworks magazine (retro), Worldwide ISO and TLD codes, File extensions database, The Hackers dictionary, Free software for the Atari, Amiga and Macintosh, Nokia smartphone, PocketPC, List of all BASIC programming language commands, List of all DOS commands, Free Advanced Bash-Scripting Guide (Linux-Unix)