User Guide > Scripting > Script Statements > Run-Time Error Trapping Statements
Was this helpful?
Run-Time Error Trapping Statements
These statements are available to assist you with run-time error trapping:
On Error GoTo Statement
 
Description
Cause a trappable run-time error to jump to a label
Syntax
On Error GoTo...
Remarks
Various parameters indicate how errors are handled. Error trapping is turned off while in the body of the error-handler routine. If a run-time error occurs while processing the original error, execution is terminated immediately.
You may find out what error was trapped by accessing the Err object. The number and description properties of the Err object are accessed in the same way as they are in Visual Basic. Err.number is the error number and Err.description is the error description. These properties can only be read, not modified.
Example
'This turns error trapping off, so a run-time error is a terminal condition:
On Error GoTo 0
'This causes a trappable run-time error to jump to the label "errlabel":
On Error GoTo errlabel
Note:  Run-time error handling is not scoped as it is in Visual Basic. If an error occurs in a user-defined function, and that function does not have an error handler, then any error handling in the caller is not activated. Instead, the run-time error causes immediate termination of processing. Control may fall through into an error handler, but in this case, you should not try to execute a Resume or Resume Next statement, as that causes an immediate, untrappable run-time error.
On Error Resume Next Statement
 
Description
Cause a trappable run-time error to jump to the next line
Syntax
On Error Resume Next...
Remarks
Various parameters indicate how errors are handled. Error trapping is turned off while in the body of the error-handler routine. If a run-time error occurs while processing the original error, execution is terminated immediately.
You may find out what error was trapped by accessing the Err Object Variable. The number and description properties of the Err object are accessed in the same way as they are in Visual Basic. Err.number is the error number and Err.description is the error description. These properties can only be read, not modified.
Example
This causes a trappable run-time error to skip the rest of the currently executing statement:
On Error Resume Next
Resume Label Statement
 
Description
Cause execution to branch back to the statement containing the label
Syntax
…Resume [Label]
Remarks
This statement is executed while in the body of an error handler. It causes error trapping to be restored to its previous state, for example: Goto errlabel. If this statement is executed while an error handler is not active, an untrappable run-time error occurs.
Error trapping is turned off while in the body of the error-handler routine. If a run-time error occurs while processing the original error, execution is terminated immediately.
Note:  Labels must be left-justified. The label Errhandler cannot be indented in an expression. If labels are indented, an "undefined label" error occurs at run time.
Example
This example causes the compiler to branch back to the Cont1 part of the code:
On Error GoTo ErrHandler
Dim Var
Var = FieldAt("/SOURCE/R1/Customer")
Cont1:
Var = "No ID"
LogMessage(Var)
Return
ErrHandler:
LogMessage("in ErrHandler")
Resume Cont18
Resume Next Statement
 
Description
Cause execution to branch back to the beginning of the statement after the statement in which the run-time error occurred
Syntax
…Resume Next
Remarks
This statement is executed while in the body of an error handler. It causes error trapping to be restored to its previous state, for example: Goto errlabel. If this statement is executed while an error handler is not active, an untrappable run-time error occurs.
Error trapping is turned off while in the body of the error-handler routine. If a run-time error occurs while processing the original error, execution is terminated immediately.
Example
This causes a trappable run-time error to skip the rest of the currently executing statement.
On Error Resume Next
Resume Statement
 
Description
Cause execution to branch back to the beginning of the statement in which the run-time error occurred
Syntax
...Resume...
Remarks
This statement is executed while in the body of an error handler. It causes error trapping to be restored to its previous state, for example: Resume Next or Goto errlabel. If this statement is executed while an error handler is not active, an untrappable run-time error occurs.
Error trapping is turned off while in the body of the error handler routine. So if a run-time error occurs while processing the original error, execution is terminated immediately.
Example
On Error GoTo errorHandller
errorHandller:
<statement for get rid of the error>
Resume
Last modified date: 08/02/2023