9 - 1 9 - 1
MELSEC-Q
9 THE CONCEPT OF ERROR HANDLING
9
9 THE CONCEPT OF ERROR HANDLING
If an error occurs while running the BASIC program, an error message is displayed
and the program stops running.
ERROR !
If an error occurs,
the program no
longer runs
Although the program is usually created to generate a minimal amount of errors taking
as many potential causes into consideration as possible, errors may occur due to
causes that are normally difficult to foresee.
Creating an “error handling routine” in BASIC to deal with these kinds of errors will
allow the program to continue running without stopping and displaying an error
message.
9.1 Definition of Error Handling
Error handling routine is a routine performed when an error occurs. It is defined using
the ON ERROR GOTO instruction. By specifying a line number or label after the ON
ERROR GOTO instruction, the routine begins executing from the line specified by this
line number or label once an error occurs.
ON ERROR GOTO
RESUME
Error handling routine
Normal processing routine
In the error handling routine, appropriate corrective action for the error can be taken
using BASIC instructions.
Once the error handling is completed, normal processing can be resumed using the
RESUME instruction.
Once the error handling is completed, always return to normal processing using
the RESUME instruction. The error handling will not be performed if an error occurs
again in case the processing is resumed using an instruction such as GOTO.
REMARK
• To disable an error handling routine that has been defined, set ON ERROR GOTO
to 0. After this, an error message is displayed and the program stops if an error
occurs.