7.1.14 On Error
- Purpose
-
The On Error statement enables or disables transfer of control to a specified label if an error occurs.
- Syntax
On Error GoTo LabelName
- Argument
-
- LabelName
-
Specify the label name of the jump destination. Use a name that complies with the variable naming conventions.
Specify 0 for LabelName to prevent control from transferring to the specified label when an error occurs.
- Description
-
The On Error statement enables an error-handling routine starting from the line following the label. If a run-time error occurs, control moves to the labeled line and processing resumes. If a syntax error occurs, however, control is not transferred to the labeled line. The specified label must exist within the same procedure as the On Error statement.
If On Error GoTo 0 is not specified, the error-handling routine starting from the line following the label is effective until the procedure terminates.
An execution error occurs if you specify a jump destination label as follows:
-
Specify an On Error statement outside the procedure and specify a jump destination label within the procedure.
-
Specify an On Error statement outside the flow control statement and specify a jump destination label within the flow control statement.
-
- Supplementary note
-
Control jumps to the label specified in an On Error statement if an execution error occurs in a statement or command that can give rise to such errors. As exceptions to this general rule, however, control is not transferred if an execution error results from either of the following:
-
End-of-file error in a TextRead command
-
Timeout in a WaitForExec command
For commands that do not give rise to execution errors, such as IsDefine and IsExistFile, control does not pass to the labeled line regardless of the command's return value.
-
- Example
On Error GoTo ErrHandler ' Hereafter, if an error occurs, ' go to the line following the label. Copy (InDir+"CTL3D32.DLL", OutDir+"CTL3D32.DLL", VersionUp) ... On Error GoTo 0 ' Hereafter, do not transfer control ' to the line following the label. ... ErrHandler: ' Error-handling jump destination ...
- JP1/Script version
-
Supported from JP1/Script 05-00.