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

# Generate Contract Errors

> Generating errors from smart contracts.

There are a number of ways to generate errors in contracts.

One way is error enum types, that are defined by contracts and that map errors to unsigned 32-bit integer values. They are usable as error values in the return types of contract functions.

> [!NOTE]
>
> The \[errors example] demonstrates how to define your own error types.

[errors example]: https://developers.stellar.org/docs/build/smart-contracts/example-contracts/errors.md

## Error Enums

Errors are a special type of enum integer type that are stored on ledger as `Error` values containing a `u32` code.

```rust theme={"theme":{"light":"github-light","dark":"github-dark"}}
#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum Error {
    AnError = 1,
}
```

When converted to XDR, the value becomes an `ScVal`, containing a `ScError`, containing the integer value of the error as contract error.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "error": { "contractError": 1 } }
```
