Basic Try-Catch
Catch errors and handle them gracefully.try-catch.yaml
- Basic error catching with
try/catch - Filtering errors by type and status code
- Communication error handling (network failures, HTTP errors)
- Preventing workflow failure on expected errors
Try-Catch with Recovery Actions
Execute recovery tasks when errors occur.try-catch-then.yaml
- Capturing error details with
as: error - Executing multiple recovery tasks in
catch.do - Emitting error events for monitoring
- Storing error in context for later use
- Conditional task execution based on error state
- Graceful degradation (skip buying if pet not found)
Retry with Backoff
Automatically retry failed operations with exponential backoff.- Inline Retry
- Reusable Retry
try-catch-retry-inline.yaml
- Automatic retry on specific error types (503 Service Unavailable)
- Initial delay configuration (3 seconds)
- Exponential backoff strategy
- Maximum retry attempts (5)
- Inline retry definition
Raising Errors
Explicitly raise errors for validation or exceptional conditions.- Inline Error
- Reusable Error
raise-inline.yaml
- Explicitly raising errors with
raise - RFC 7807 Problem Details format
- Custom error types
- HTTP status codes
- Dynamic error messages with expressions
Conditional Error Handling
Combine conditionals with error raising for validation.conditional-task.yaml
- Conditional error raising based on business rules
- Early workflow termination with
then: end - Input validation before processing
- Preventing invalid operations
Error Type Filtering
Handle different error types with different strategies.- Multiple catch blocks for different error types
- Different handling strategies per error type
- Retrying transient failures (503)
- Logging validation errors (400) without retry
Error Context and Debugging
Capture comprehensive error information for debugging.- Capturing full error details
- Including workflow metadata in error events
- Workflow instance identification
- Context snapshot at error time
- Timestamp for error correlation
Summary
Robust error handling requires:- Try-Catch - Catch and handle errors gracefully
- Retry Logic - Automatically retry transient failures
- Backoff Strategies - Exponential backoff prevents overwhelming services
- Error Raising - Explicit error creation for validation
- Error Filtering - Handle different errors differently
- Error Context - Capture sufficient information for debugging
- Recovery Actions - Compensating logic when errors occur
- Graceful Degradation - Continue workflow with reduced functionality