On error goto

[<<<] [>>>]

The error handling instructions that ScriptBasic have are the usual and well known ON ERROR GOTO constructs. The easiest example using this construct is:

ON ERROR GOTO ErrorHappens

ERROR 1

PRINT "This won't print\n" ErrorHappens: PRINT "This is the error message.\n"

END

will print

This is the error message.

The error is caused by the statement error, which artificially generates an error of the code given on the line after the keyword. The statement ON ERROR GOTO declares where to continue execution when an error happens. The execution system remembers this and starts to execute the code after the label, when an error happens.

To switch off the effect of the ON ERROR GOTO statement you can execute a command

ON ERROR GOTO NULL

Note that other BASIC implementations use the label 0 and the form on error goto 0. However in ScriptBasic this means to jump to the label 0 in case of an error. This label is completely valid in ScriptBasic though its use is not recommended. The form

ON ERROR GOTO NULL

used in ScriptBasic is more readable and expresses the real meaning not to jump anywhere in case of error, but rather handle the error the normal way.


[<<<] [>>>]