• Discover
  • Partner with us
  • Chapters
  • Blog

Learn everything about Scroll

Course Introduction

Web1 and Web2
The Middleman
Blockchain Comes Into Play
Web3 As a New Iteration for Web
Web3 Use Cases
The Architecture of a dApp
The Architecture of Web2 Apps

What is ZKP
Submit Your Homework 1
ZKP Tools: Zk-SNARK
ZkSNARK: Under the Hood (Optional)
ZKP Tools: Zk-STARK
ZkSTARK: Under the Hood (Optional)
Applied ZK: Noir
Applied ZK: Circom
Intro to ZK Development
Quiz 1

Scroll & Ethereum
Submit Your Homework 2

Smart Contract Basic and Remix IDE
Introduction to Solidity
Variables and Data Types
Variables and Data Types - Part 2
Functions and Modifiers
Control Flow
Error Handling
Inheritance
Interface
Smart Contract Demo
Deploying Smart Contract to Scroll
Submit Your Homework 3
Bonus: Oracles

zkEVM
Execution Node
Rollup Node
Prover Network
Rollups
Bridge Contracts
Quiz 2

Submit Your Final Project

In Solidity, error handling is crucial for controlling contract execution and managing state under failure conditions. Effective error handling prevents contracts from executing unintended actions and ensures that users receive meaningful feedback when operations fail.

Let’s start with a quick introduction on error handling.

Introduction to Error Handling

Error handling in Solidity involves several key mechanisms:

1. Revert: Reverts the transaction and undoes all changes made to the state, while providing an error message.

2. Require: A shorthand for reverting the transaction if a condition is not met.

3. Assert: Used to test for internal errors and invariants; reverts the transaction if a condition evaluates to false.

4. Try/Catch: Handles exceptions in external function calls and contract creations.

Revert

The revert statement stops execution and reverts any changes made to the state during the transaction. It also allows you to provide an error message.

function buyItem(uint itemId) public payable {

    if (msg.value < items\[itemId\].price) {

        revert("Payment is not enough.");

    }

    // Continue with purchase logic

}

Require

You have already seen require in the Modifiers lesson. For a quick reminder, let’s take another look at it if you need a refresher.

Require is used to assert conditions before executing an operation. If the condition is false, the operation is reverted and a specified error message is returned. It is most commonly used to validate inputs and conditions.

function withdraw(uint amount) public {

    require(amount <= balances\[msg.sender\], "Insufficient balance.");

    balances\[msg.sender\] -= amount;

    payable(msg.sender).transfer(amount);

}

Assert

Assert is used for checking invariants and internal conditions that should never fail if the contract functions correctly. It consumes all gas when an assertion fails, signaling a critical error.

function divide(uint a, uint b) public pure returns (uint) {

    assert(b != 0);  // Prevent division by zero

    return a / b;

}

Try/Catch

Introduced in Solidity 0.6, `try/catch` blocks allow handling exceptions from external contract calls or contract creations using `new`.

interface IExternalContract {

    function someFunction(uint x) external returns (bool);

}

contract Caller {

    IExternalContract externalContract;

    constructor(address \_contractAddress) {

        externalContract = IExternalContract(\_contractAddress);

    }

    function callExternalFunction(uint x) public returns (bool) {

        try externalContract.someFunction(x) {

            return true;

        } catch {

            // Handle the case where the call fails

            return false;

        }

    }

}

Do not worry if you have not understood the interface. You will see the interface in the next lesson.

Before finalizing this lesson, let’s have a look at the best practices.

Best Practices in Error Handling

  • Use require for input validation or conditions that must be met for the function to proceed.
  • Use assert to check for conditions that indicate a bug in the contract code.
  • Handle potential failures in external calls using try/catch.
  • Provide clear and informative error messages to help with debugging and user interaction.

In summary, effective error handling is crucial for developing robust and secure smart contracts. It ensures that contracts only perform intended actions and provide useful feedback, thereby enhancing the security and reliability of your applications.

Previous
Next

Lesson discussion

Swap insights and ask questions about “Learn everything about Scroll”.

Enroll to participate
Start the course to unlock the discussion. Enrolling helps us keep conversations relevant to learners.
WebsiteDiscoverPartner with UsBlogEvents
Discover
CoursesCircleRustSoliditySolanaWeb3 FundamentalsBlockchain Basics
CompanyAbout UsBrand GuidelineFAQsTerms of UsePrivacy PolicyGDPR NoticeCookies
Don't miss any update!

Disclaimer: The information, programs, and events provided on https://risein.com is strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice, nor do we make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://risein.com disclaims any responsibility for financial decisions made by users based on the information provided here.

© 2026 Rise In, All rights reserved