TRY Step
The try step provides robust error handling and recovery within your Flow Services. It allows you to execute a block of steps and catch any errors that occur.
Properties
| Property | Type | Description |
|---|---|---|
| type | string | Must be "try" |
| steps | array | Nested steps to attempt |
| catch | array | (Optional) Steps to execute if steps fail. If omitted, errors are still absorbed. |
Overview
Joynare Nexus implements TRY/CATCH semantics where the try block executes first. If it fails, the catch block is executed, and the original error is absorbed if the catch succeeds.
Schema
yaml
- type: "try"
steps:
- type: "invoke"
service: "system.http:Request"
input:
url: "https://api.example.com/data"
catch:
- type: "map"
set:
status: "fallback"
data: {}How It Works
- Execute TRY Block: The steps in
stepsare executed first. - Handle Error: If any step fails, the error is injected into the pipeline as
_error. - Execute CATCH Block: The steps in
catchare executed with access to_error. - Absorb or Propagate: If catch succeeds, execution continues. If catch fails, the error propagates.
Error Injection
When an error occurs in the try block, the error message is automatically injected into the pipeline:
yaml
pipeline:
output:
errorMessage: string
steps:
- type: "try"
steps:
- type: "invoke"
service: "external:UnreliableService"
catch:
- type: "map"
set:
errorMessage: "${_error}"Common Use Cases
API Error Handling
yaml
steps:
- type: "try"
steps:
- type: "invoke"
service: "system.http:Request"
input:
url: "${apiUrl}"
method: "GET"
catch:
- type: "map"
set:
responseData: null
status: "unavailable"Graceful Degradation
yaml
steps:
- type: "try"
steps:
- type: "invoke"
service: "premium:CalculateDiscount"
input:
customerId: "${customerId}"
catch:
- type: "invoke"
service: "system.math:Multiply"
input:
value1: "${orderTotal}"
value2: 1.0Try Without Catch (Silent Failure)
yaml
steps:
- type: "try"
steps:
- type: "invoke"
service: "analytics:TrackEvent"
input:
event: "user_action"
# If analytics fails, we don't care - continue anywayCatch Block Behavior
With Catch Block
If a catch block is defined and the try block fails:
- The error message is injected as
_errorinto the pipeline - The catch block steps are executed
- If catch succeeds, the error is absorbed and flow continues
- If catch fails, a new error is returned: "catch block failed: [original error]"
Without Catch Block
If no catch block is defined and the try block fails:
- The error is still absorbed (not propagated)
- Execution continues to the next step
- This is useful for "fire and forget" operations where failures are acceptable
Key Points
- The
_errorvariable contains the error message from the failed step. - Exit signals (from
exitstep with ExitError type) are not caught and will propagate correctly. - Catch block is optional. Without it, errors are silently absorbed.
Real-World Example
See flows/showcase/07-error-handling/Reliability/flow.yaml for a complete example demonstrating:
- Try-catch with timeout handling
- Error recovery with
_errorvariable - Integration with retry policies
