17.07.2013 Views

GWBASIC User's Manual

GWBASIC User's Manual

GWBASIC User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GW-BASIC <strong>User's</strong> Guide<br />

ON ERROR GOTO Statement<br />

Purpose:<br />

To enable error trapping and specify the first line of the error-handling subroutine.<br />

Syntax:<br />

ON ERROR GOTO line number<br />

Comments:<br />

Once error trapping has been enabled, all errors detected by GW-BASIC, including direct mode<br />

errors, (for example, syntax errors) cause GW-BASIC to branch to the line in the program which<br />

begins the specified error-handling subroutine.<br />

GW-BASIC branches to the line specified by the ON ERROR statement until a RESUME statement<br />

is found.<br />

If line number does not exist, an "Undefined line" error results.<br />

To disable error trapping, execute the following statement:<br />

ON ERROR GOTO 0<br />

Subsequent errors print an error message and halt execution.<br />

An ON ERROR GOTO 0 statement in an error-trapping subroutine causes GW-BASIC to stop and<br />

print the error message for the error that caused the trap. It is recommended that all error-trapping<br />

subroutines execute an ON ERROR GOTO 0 if an error is encountered for which there is no<br />

recovery action.<br />

If an error occurs during execution of an error-handling subroutine, the GW-BASIC error<br />

message is printed and execution terminated. Error trapping does not occur within the errorhandling<br />

subroutine.<br />

Examples:<br />

10 ON ERROR GOTO 1000<br />

.<br />

.<br />

.<br />

1000 A=ERR: B=ERL<br />

1010 PRINT A, B<br />

1020 RESUME NEXT<br />

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

file:///C|/Documents%20and%20Settings/Lorenzo/Desktop/GW%20Basic/ONERROR.html (1 of 2)28/03/2004 21.29.39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!