Cairo by Example
/
GitHubGitHub
/
  • Welcome
  • Cairo
    • Allocating Memory
    • Arrays
    • Assert
    • Error Messages
      • #Example
    • Functions
    • Hints
    • If / Else
    • Implicit Arguments
    • Imports
    • Inputs
    • Jumps
    • Memory
    • Namespaces
    • Outputs
    • Pointers
    • Recursion
    • Registers
    • Signature Verification
    • Strings
    • Structs
    • Tuples
    • Variables
  • StarkNet
    • Authentication
    • Block Information
    • Caller Address
    • Constructor
    • Contract Address
    • Contract Calls
    • Events
    • Hello World
    • L1 -> L2
    • L2 -> L1
    • Library Calls
    • Mappings
    • Storage
    • Transaction Information
    • Visibility
  • SHARP
    • Generating Proofs
    • Verifying Proofs
  • Welcome
  • Cairo
    • Allocating Memory
    • Arrays
    • Assert
    • Error Messages
      • #Example
    • Functions
    • Hints
    • If / Else
    • Implicit Arguments
    • Imports
    • Inputs
    • Jumps
    • Memory
    • Namespaces
    • Outputs
    • Pointers
    • Recursion
    • Registers
    • Signature Verification
    • Strings
    • Structs
    • Tuples
    • Variables
  • StarkNet
    • Authentication
    • Block Information
    • Caller Address
    • Constructor
    • Contract Address
    • Contract Calls
    • Events
    • Hello World
    • L1 -> L2
    • L2 -> L1
    • Library Calls
    • Mappings
    • Storage
    • Transaction Information
    • Visibility
  • SHARP
    • Generating Proofs
    • Verifying Proofs
Edit this page on GitHub
Cairo
Error Messages

Error Messages

Error messages can be implemented via a concept called "Scope Attributes".

Scope Attributes allow the definition of code blocks via the with_attr statement.

Only local variables can be accessed within the new code block. String interpolation of local variables is possible via {}.

Example

func main():
    alloc_locals

    local x = 1

    # Error messages will be shown in the standard output during the program's runtime.
    with_attr error_message("The value of `x` should be 42 but it's {x}."):
        assert x = 42
    end

    return ()
end
Assert
Functions
MIT 2022 © Philipp Muens.