Aptos Move by Example
  • 🚀Getting Started
  • Set-Up
  • Why is Move Secure
    • Move prover
  • Move vs Solidity
    • Resources
    • Parallel Processing
    • Reentrancy attacks
    • Memory management
    • Smart contract verification
    • Compiled language
  • Basic Concepts
    • Move.toml
    • Primary data-types
    • Strings
    • Comments
    • Functions
    • Function Visibilities
    • Control flow and expressions
    • Loops
    • Error
    • Struct and its Abilities
    • Scripts
    • Operations
  • Intermediate Concepts
    • Local variables
    • Constants
    • Signer
    • Vector
    • Address
    • Uses and Aliases
    • Maps
    • Hash functions
    • References
    • Unit test
    • Generics
    • Type Arguments
    • Type Inference
  • Advanced Concepts
    • Global Storage Structure
    • Global Storage Operations
    • Phantom Type Parameters
    • Timestamps
    • Ownership
    • Move coding conventions
    • View functions
    • Aptos account
    • Aptos Coin
    • Aptos Token(Nft)
    • Object
    • Token V2
  • Applications
    • First App
    • ToDoList
    • Voting System
    • Basic Tokens
    • Storage using Generics
    • Company
    • Collection
    • Football Card
    • Staking Module
    • MultiSender Wallet
    • English Auction
    • Dutch Auction
    • Attendance Sheet
    • Polling Contract
    • Lottery Contract
  • Decentralized Finance
    • Simple Swap Protocol Contract
    • Code of Swapping Protocol
  • Hacks
    • Coming soon
  • Hands on tutorials
    • Indexer tutorials
Powered by GitBook
On this page
Edit on GitHub
  1. Basic Concepts

Error

You can throw an error by calling assert and abort.

Abort:

abort error_code //error code is of type u64

module my_addrx::Errors
{
    use std::debug::print;
    use std::string::utf8;

    fun isEven(num:u64)
    {
        if(num%2==0)
        {    
            print(&utf8(b"No Error as the Number is Even"));
        }
        else    
        {    
            abort 11 //throwing error as the given number is not even
        }
    }

    #[test]
    fun testing()
    {
        isEven(3);
    }
}

Assert:

assert!(expression: bool, error_code: u64)

module my_addrx::Errors
{

    fun isEven(num:u64)
    {
        assert!(num%2==0,11);
    }

    #[test]
    fun testing()
    {
        isEven(3);
    }
}
PreviousLoopsNextStruct and its Abilities

Last updated 2 years ago