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

# Handle failures

> What happens when something fails, and how to go another way.

## When a step fails

If a step's function throws, the SDK saves the error and throws a `StepError` with the same message. Leave it, and the run fails. Catch it to go another way:

```ts theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import { StepError } from '@nelkap/sdk';

export async function chargeOrder(orderId: string) {
  try {
    await nelkap.step.run('charge', () => chargeCard(orderId));
  } catch (error) {
    if (!(error instanceof StepError)) {
      throw error;
    }

    await nelkap.step.run('payment failed email', () => sendPaymentFailedEmail(orderId));

    return;
  }

  await nelkap.step.run('shipping', () => shipOrder(orderId));
}
```

On every call after, the failed step throws the same `StepError` without running again. Your code takes the same path each time.

## When a run fails

A run fails when your workflow throws. Its message shows under Error on the run's page.

Nelkap can also stop a run, with a reason of its own. See [Errors](https://docs.nelkap.com/reference/errors.md#run-failures).

## When Nelkap turns a call down

`run` and `emit` throw a `NelkapError` that names the reason. Inside a workflow, a step Nelkap turns down throws one too. See [Errors](https://docs.nelkap.com/reference/errors.md).

## Short outages

If the SDK can't reach Nelkap, or Nelkap asks it to slow down, the run doesn't fail. It stops where it is, and Nelkap picks it back up a few minutes later, from its last saved step.

## Run it again

Once the cause is fixed, [replay](https://docs.nelkap.com/guides/start-runs.md#replay-a-run) the run from its page.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.