ON END defines an event branch to an error handler for end-of-file conditions. An end-of-file error occurs when you attempt to ENTER data and there is no more data in a file, or when a random access OUTPUT or ENTER requires more bytes than the record size. You could also trap this error (59) with a general purpose ON ERROR handler, but this might require additional logic to test for specific errors.
ON END is canceled by OFF END but it is not disabled by DISABLE. It is also canceled by a SUBEXIT, SUBEND, or RETURN from the defining subprogram.
When returning from a CALL or GOSUB execution continues with the line following the line causing the end-of-file.
Common Information for ON END, ERROR, TIMEOUT
The line number or line label following the GOTO, GOSUB, or RECOVER or the subprogram name following the CALL indicates where to transfer control when the event occurs. Line numbers or labels must be in the same subprogram as the ON statement. RECOVER causes the program to SUBEXIT from subprograms as needed to return to the defining subprogram and then does a GOTO to the specified program line. (The defining subprogram is the subprogram with the ON statement.)
The ON END and ON TIMEOUT events have a fixed priority of fifteen and ON ERROR has a fixed priority of seventeen. However, when one of these events occurs, the current SYSTEM PRIORITY is ignored and the branch occurs immediately. The only exception is when an error occurs when the system priority is already seventeen; this "double fault" condition can not be trapped.
When an event branch is taken the system priority is changed depending on the branch type. With a GOTO the system priority is not changed. With a RECOVER the system priority is only changed if any SUBEXITs are performed, in which case the system priority is restored to the value when the defining subprogram called another subprogram. With a CALL or GOSUB the system priority is changed to fifteen for ON END and ON TIMEOUT or seventeen for ON ERROR. When returning from the CALL or GOSUB the system priority is restored to the value before the branch was taken.
If other subprograms have been called from the defining subprogram when the event occurs, the action taken depends on the branch type. CALL or RECOVER branches can still occur as soon as the event occurs. (Although branches are not taken in the middle of execution of a line; the branch is taken between lines.) GOTO or GOSUB branches can not be taken so an error occurs.