> ## Documentation Index
> Fetch the complete documentation index at: https://docs.threadify.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Capturing Failures

> Properly record caught business logic/app failures in your workflows

### Recording Failures

<CodeGroup>
  ```javascript JavaScript theme={null}
  const step = thread.step('payment_processed');

  try {
    const payment = await processPayment(orderId);
    await step.addContext(payment).success();
  } catch (error) {
    await step.failed({ 
      message: error.message,
      errorCode: 'PAYMENT_FAILED',
      retryable: true
    });
  }
  ```

  ```go Go theme={null}
  paymentStep := thread.Step("payment_processed")
  payment, err := processPayment(orderId)
  if err != nil {
      _, stepErr := paymentStep.Failed(ctx, map[string]any{
          "message":   err.Error(),
          "errorCode": "PAYMENT_FAILED",
          "retryable": true,
      })
      if stepErr != nil {
          log.Fatal(stepErr)
      }
      return
  }
  _, err = paymentStep.AddContext(payment).Success(ctx)
  if err != nil {
      log.Fatal(err)
  }
  ```

  ```python Python theme={null}
  payment_step = thread.step("payment_processed")
  try:
      payment = await process_payment(order_id)
      await payment_step.add_context(payment).success()
  except Exception as error:
      await payment_step.failed({
          "message": str(error),
          "errorCode": "PAYMENT_FAILED",
          "retryable": True
      })
  ```
</CodeGroup>

### Retry Tracking

Each retry attempt is automatically tracked in step history for debugging.

### Next Steps

<CardGroup cols={2}>
  <Card title="External References" icon="link" href="/core-concepts/external-references">
    Link workflows to external systems
  </Card>

  <Card title="Sub-steps" icon="list-tree" href="/core-concepts/sub-steps">
    Break down complex operations
  </Card>
</CardGroup>
