11 - 162 11 - 162
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
ON ERROR GOTO
Instruction
ON ERROR GOTO
• Enables interrupt processing if an error occurs and moves the execution to the starting line
of an error handling routine.
ON ERROR GOTO <line number>
Syntax
line number
• • • •
Specify the starting line number or label of the error
handling routine of the program that will be executed
if an error occurs.
Examples
ON ERROR GOTO 100
• • • •
Moves the execution to line 100 if an error occurs.
Description
• The ON ERROR GOTO instruction enables interrupt processing if an error occurs and
moves the execution to the start line of an error handling routine.
• A label name can be specified instead of a line number for <line number>.
• If the specified <line number> does not exist, an “Undefined line number” error occurs.
• Do not display characters or switch ports via the ZIDV or ZODV instruction in the error
handling routine.
Character display and input/output processing may not be performed correctly upon
returning to the main program, depending on the execution timing of the error handling
routine.
• Specify 0 for the value in <line number> before executing the program in order to disable a
previously enabled interrupt at error generation.
Then, if the program detects an error, it displays the error message and stops the
execution of the program.
• If "ON ERROR GOTO 0" is present in an error handling routine, the errors that have
occurred are displayed and the execution of the program stops.
• It is recommended to specify "ON ERROR GOTO 0" if an error that is not handled explicitly
in the error handling routine is detected.
• Use the RESUME instruction to return from the error handling routine.
• If an error occurs during the execution of an error handling routine, BASIC displays the
corresponding error message and the execution of the program stops.