Contents |
Effect
Jumps to a specified line of an error handling routine, whenever an eror occurs.
It's useful in the following situations:
- for defined errors in MSX-BASIC and Disk Basic, you want to avoid the display of the error messages
- for non-defined errors, you decide to define them and to handle them directly in your program
Syntax
ON ERROR GOTO <LineNumber>
Parameter
<LineNumber> is a program line number of your error handling routine. If you excute ON ERROR GOTO with 0 as line number, it cancels the effect of the ON ERROR GOTO executed previously, stops the execution of the program and displays the error in progress. Placed alone in the last line of your program, this will have the effect of disabling the error handling routine of your program when execution is interrupted.
Examples
If you create the file named "MYDISK" for example with BSAVE"MYDISK",0,0,S the following program will be able to detect if this is your disk that is inserted or not.
10 ON ERROR GOTO 1000 20 BLOAD"MYDISK",S 30 PRINT"This is the right disk. :)" 40 END 1000 IF ERL<>20 THEN ON ERROR GOTO 0 1010 IF ERR=70 THEN PRINT"Insert a disk!" 1020 IF ERR=53 THEN PRINT"This disk is not the right one!" 1030 RESUME 40
Alternate code with the same effect:
10 ON ERROR GOTO 1000 20 BLOAD"MYDISK",S 30 PRINT"This is the right disk. :)" 40 END 1000 IF ERL<>20 THEN 1040 1010 IF ERR=70 THEN PRINT"Insert a disk!" 1020 IF ERR=53 THEN PRINT"This disk is not the right one!" 1030 RESUME 40 1040 ON ERROR GOTO 0
There is another example of use here.
Related to
Compatibility
MSX-BASIC 1.0 or higher