Prompt
How do I handle exceptions in a workflow without breaking it
Latest observation
Oct 16, 2026
OpenAI APIWeb search: off
To handle exceptions in a workflow without breaking the whole process, the key idea is to catch failures at the right scope, log or record them, and then decide whether to continue, retry, compensate, or route to an alternate path.
General approach
-
Catch exceptions locally
- Wrap risky steps in their own
try/catchblocks. - This prevents one failed step from aborting the entire workflow.
- Wrap risky steps in their own
-
Classify the exception
- Determine whether it is:
- Transient: temporary issues like network timeouts
- Permanent: invalid input, missing data, unauthorized access
- Transient errors can usually be retried.
- Permanent errors usually should be handled with fallback logic or sent to an error path.
- Determine whether it is:
-
Use fallback paths
- If a step fails, continue with:
- default values
- alternate services
- manual review
- skipping optional steps
- If a step fails, continue with:
-
Retry when appropriate
- Add retry logic with backoff for unstable operations.
- Avoid retrying non-recoverable errors.
-
Record the failure
- Log the error details.
- Store status in a database, queue, or workflow state so the process remains observable.
-
Isolate critical and non-critical steps
- Only let truly fatal errors stop the workflow.
- Non-essential steps should fail independently.
-
Use compensation if needed
- If a later step fails after earlier steps succeeded, undo or compensate for prior actions.
Example pattern
Pseudocode
try:
result = step_one()
except Exception as e:
log_error(e)
result = default_value
try:
step_two(result)
except TransientError:
retry_step_two()
except Exception as e:
send_to_dead_letter_queue(e)
If you’re using a workflow engine
Many tools support this directly:
- BPMN/Camunda/Zeebe: boundary error events, retries, escalation flows
- Temporal: retry policies, activity error handling, compensation
- Airflow: task retries, trigger rules, downstream continuation
- AWS Step Functions:
CatchandRetryblocks - Prefect/Dagster: task-level retries and failure handlers
Good practice
- Handle exceptions close to where they occur
- Don’t swallow errors silently
- Make failure handling explicit
- Keep the workflow idempotent so retries are safe
If you want, I can show you how to do this in a specific workflow system or language, like Python, JavaScript, Temporal, Airflow, or BPMN.