Wraps a block of statements where errors may occur. Statements in the Try block run until an error occurs. If an error occurs, the Errors pane, status tool, run report, and Err object are updated with error information and playback continues with statements in the Catch block. The Catch block only runs if an error occurs. Statements in the Finally block always run even if errors do not occur.
Catch or Finally must be specified after Try. One Catch or Finally block is allowed in a Try statement, but Finally must be used last to avoid a syntax error. Try...Catch...Finally statements can be nested in other Try...Catch...Finally statements. If a Catch block is not included before a Finally block, the next Catch block up the call stack runs after the Finally statements run.
Syntax
Try
[TryStatements]
Catch
[CatchStatements]
Finally
[FinallyStatements]
End Try
Arguments
| Argument | Description |
|---|---|
| TryStatements | Statements where an error may occur. |
| CatchStatements | Statements to handle errors that occur in the Try block. Optional if Finally statements are used. |
| FinallyStatements | Statements to run after all other error processing occurs. Optional if Catch statements are used. |
Example
Try
If x <> y Then
Fail("x does not equal y")
End If
Catch
x = y
Finally
PrintLn("x equals y")
End Try