Skip to main content
Version: v0.18.0

Try

Alias:Try, TryTo

Output:T

Tries to execute a step and recovers if that step results in failure.

ParameterTypeRequiredPositionDefault ValueSummary
Statement
Sequence
Do
T✔1The statement to try.
Recover
OnError
stringReturns the default value of the return type.The action to perform on an error.

Examples​

Example 1​

SCL​

Try (1 / 0) OnError: 0

Expected Logs​

Error Caught in Divide: Attempt to Divide by Zero.

Expected Output​

0

Example 2​

SCL​

Try (4 / 2)

Expected Output​

2

Example 3​

If the alternative is not set the default value is used.

SCL​

Try (1 / 0)

Expected Logs​

Error Caught in Divide: Attempt to Divide by Zero.

Expected Output​

0

Example 4​

SCL​

Try (ArrayElementAtIndex [0,1,2,3] 4 ) OnError: 4

Expected Logs​

Error Caught in ArrayElementAtIndex: Index was outside the bounds of the array.

Expected Output​

4

Example 5​

SCL​

TryTo Do: (
- log 123
- log 1 / 0
- 4
) OnError: 5

Expected Logs​

123
Error Caught in Sequence: Attempt to Divide by Zero.

Expected Output​

5