Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Latest commit

 

History

History
63 lines (49 loc) · 1.68 KB

errors.mdx

File metadata and controls

63 lines (49 loc) · 1.68 KB
sidebar_position title description sidebar_custom_props
90
Errors
Generating errors from smart contracts.
<title>Generating errors from smart contracts.</title>

:::danger These are not the droids you're looking for

This page has been migrated to the Stellar Developers documentation. Please click here for the most up-to-date information

:::

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.

:::info

The [errors example] demonstrates how to define your own error types. [errors example]: ../tutorials/errors.mdx

:::

Error Enums

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

#[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 ScStatus, containing the integer value of the error as contract error.

{ "status": { "contractError": 1 } }