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

# Error Handling

> SDKException, codes, and recovery

Everything the SDK throws is an `SDKException`, wrapping a proto-backed error so the same code
and category cross every language binding.

```ts theme={"theme":"css-variables"}
import { RunAnywhere, SDKException } from '@runanywhere/core'

try {
  const result = await RunAnywhere.llm.generate(prompt)
} catch (error) {
  if (error instanceof SDKException) {
    console.log(error.code, error.message)
  }
}
```

## Codes worth handling

| Code | Meaning | What to do |
| - | - | - |
| `notInitialized` | Called before `initialize()` | Initialize first |
| `modelNotFound` | No such model | Check the id, or register it |
| `networkUnavailable` | Download needs a connection | Retry when online |
| `insufficientStorage` | Not enough disk | Free space or use a smaller model |
| `insufficientMemory` | Model will not fit in RAM | Unload something first |
| `microphonePermissionDenied` | No mic access | Send the user to Settings |
| `timeout` | Took too long | Retry |
| `invalidApiKey` | Credentials rejected | Check the key |
| `cancelled` | The caller cancelled | Usually ignore |
| `invalidState` | Wrong order of operations | Read the message |
| `unsupportedCapability` | Not implemented in this build | See below |

## unsupportedCapability

```ts theme={"theme":"css-variables"}
// Throws: constrained decoding is not wired in
await RunAnywhere.llm.generateStructured(prompt, schema, 'constrained')
```

## Errors in streams

```ts theme={"theme":"css-variables"}
try {
  for await (const event of RunAnywhere.llm.generateStream(prompt)) {
    if (event.type === 'textDelta') setText((t) => t + event.text)
  }
} catch (error) {
  showError(error)
}
```

## Cancellation

Breaking out of the loop cancels the request and is not an error. Track unmount so a late
event does not set state on a gone component:

```tsx theme={"theme":"css-variables"}
const cancelled = useRef(false)
useEffect(
  () => () => {
    cancelled.current = true
  },
  []
)

for await (const event of RunAnywhere.llm.generateStream(prompt)) {
  if (cancelled.current) break
  if (event.type === 'textDelta') setText((t) => t + event.text)
}
```

## Errors are not always the SDK

Several failures on a phone look like SDK errors and are not:

| Symptom | Cause |
| - | - |
| Nothing loads on an emulator | No arm64 native libraries for these backends |
| `MLX.register()` returns false | MLX needs physical iOS hardware |
| Microphone request fails | Permission not granted at runtime |
| Download fails on cellular | The OS transfer policy, not the SDK |

## Reporting

```ts theme={"theme":"css-variables"}
catch (error) {
  if (error instanceof SDKException) {
    analytics.track('sdk_error', { code: String(error.code) });
  } else {
    throw error;
  }
}
```

Rethrow what you did not recognise.


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