Overview
The@catch decorator allows steps to continue executing even if they fail. This is essential for building resilient workflows that can handle partial failures gracefully.
Basic Usage
@catch, if risky_operation() fails, the entire flow fails. With @catch, the flow continues to the next step.
Capturing Exceptions
Store the exception in an artifact:How @catch Works
The decorator intercepts failures after all retries are exhausted:- Retries happen first (if configured)
- After all retries fail,
@catchactivates - The exception is stored (if
varis specified) - Flow continues to the next step
Catch Parameters
var: Exception Variable
print_exception: Control Logging
Limitations
No Catch on Foreach Splits
@catch on the step that creates the foreach:
@catch to the foreach step itself:
No Catch on Switch Steps
@catch:
Error Handling in Foreach
Individual Task Failures
Each foreach task can fail independently:Handling Multiple Failures
Error Handling in Branches
Parallel Branch Failures
Retry Behavior
@catch works with @retry:
- First attempt fails → retry 1
- Retry 1 fails → retry 2
- Retry 2 fails → retry 3
- Retry 3 fails →
@catchcatches the exception
Exception Information
The stored exception is wrapped:Best Practices
1. Use Specific Error Variables
2. Always Check Error State
3. Provide Fallback Logic
4. Log Failures for Monitoring
5. Graceful Degradation
Common Patterns
Retry Pattern
Optional Step Pattern
Best Effort Pattern
Circuit Breaker Pattern
Debugging Failed Steps
When a step fails but is caught:Next Steps
FlowSpec
Learn more about the FlowSpec base class
Foreach
Handle errors in parallel foreach tasks
Branching
Manage failures across parallel branches
Data Management
Understand artifact behavior with errors
