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

# Error codes

> Built-in Anchor error codes and custom error handling

Anchor provides built-in error codes and supports custom error definitions.

## Custom errors

Define custom errors with `#[error_code]`:

```rust theme={null}
#[error_code]
pub enum ErrorCode {
    #[msg("Invalid authority")]
    InvalidAuthority,
    #[msg("Insufficient funds")]
    InsufficientFunds,
    #[msg("Value exceeds maximum")]
    ValueTooLarge,
}
```

### Error codes

Custom errors start at code 6000:

* First error: 6000
* Second error: 6001
* And so on...

## Anchor framework errors

Common built-in errors:

| Code | Error                          | Description                                             |
| ---- | ------------------------------ | ------------------------------------------------------- |
| 100  | InstructionMissing             | 8 byte instruction identifier not provided              |
| 101  | InstructionFallbackNotFound    | Fallback functions are not supported                    |
| 102  | InstructionDidNotDeserialize   | The program could not deserialize the given instruction |
| 103  | InstructionDidNotSerialize     | The program could not serialize the given instruction   |
| 140  | ConstraintMut                  | A mut constraint was violated                           |
| 141  | ConstraintHasOne               | A has\_one constraint was violated                      |
| 142  | ConstraintSigner               | A signer constraint was violated                        |
| 143  | ConstraintRaw                  | A raw constraint was violated                           |
| 144  | ConstraintOwner                | An owner constraint was violated                        |
| 2000 | AccountDiscriminatorAlreadySet | The account discriminator is already set                |
| 2001 | AccountDiscriminatorNotFound   | No 8 byte discriminator was found                       |
| 2002 | AccountDiscriminatorMismatch   | 8 byte discriminator did not match                      |
| 2003 | AccountDidNotDeserialize       | Failed to deserialize the account                       |
| 2004 | AccountDidNotSerialize         | Failed to serialize the account                         |
| 3000 | DeclaredProgramIdMismatch      | The declared program id does not match                  |

See the [complete error list](https://github.com/solana-foundation/anchor/blob/master/lang/src/error.rs) in the source code.

## Using errors

```rust theme={null}
pub fn update(ctx: Context<Update>) -> Result<()> {
    require!(
        ctx.accounts.data.authority == ctx.accounts.user.key(),
        ErrorCode::InvalidAuthority
    );
    Ok(())
}
```

See [Error Handling](/guides/errors) for more details.
