NAME

on error - enable error trapping and handling

SYNOPSIS

on error goto LineNum
on error goto LineLab

DESCRIPTION

LineNum or LineLab is the line number or label of the first line of the error handling routine.  Errors that are encountered when error trapping is not enabled will cause an error message to be printed and will halt program execution.  With error trapping enabled, any error detected during execution will cause a jump to the error handling subroutine beginning at LineNum or LineLab.  Execute on error goto 0 to disable error trapping.  An on error goto 0 statement that appears in an error trapping subroutine causes Basmark QuickBASIC to stop and print the error message for the error that caused the trap.  Error trapping does not occur within an error handling subroutine.  If, however, an error does occur during the execution of an error handling subroutine, an error message is printed and execution terminates.  Use the resume statement to exit from the error trapping routine. 

In general, a line number or label reference within a subprogram must refer to a line also within the subprogram.  The on error goto statement is an exception.  Even within a subprogram, the line number or label reference of this statement must refer to a line outside any subprogram.  Upon completion, the error recovery routine is responsible for seeing that execution resumes within the subprogram which caused the error lest the control structure of the program be corrupted. 

A moduleís error handling routines are private to the module.  An on error goto statement executed within one module does not effect code in other modules.  The possibility (and opportunity) exists to have an error handling routine in each of several modules concurrently identified and prepared to execute in case of error.  Transfer of control between modules due to error handling is impossible. 

EXAMPLE

The example
	  data 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7
	  on error goto 6
	5 read a
	  print a
	  goto 5
	6 restore
	  resume
	7 end
traps the common error of attempting to read beyond the end of data. 

SEE ALSO

error, resume, erl, err

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber