SlideShare a Scribd company logo
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
S O L I D I T Y
E R R O R H A N D L I N G
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
Error Handling
How to do
error handling
in solidity
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
Error Handling
require
assert
revert
throw
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
require
Here we check the conditions and revert the state in case condition does not met.
This is most commonly used in solidity for error handling
This does not consume any gas
Syntax
require(condition, errorMessage)
Example
require(newBalance > minimumBalance, "Your do not have minimum balance in your account")
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
assert
Prevent anything really bad from happening.
This does consume all the gas and revert the state
Syntax
assert(condition)
Example
assert(balance %2 == 0)
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
revert
This revert the state along with error message
Syntax
revert("failure reason")
Example
revert("you do not have sufficient balance" )
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
throw
This is used to revert the state but this is depreciated now
Syntax
throw
Example
throw;

More Related Content

PPTX
Smart Contract & Ethereum
PDF
Introduction To Solidity
PPTX
Introduction to Blockchain and Smart Contracts
PDF
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
PPTX
Blockchain consensus algorithms
PPTX
Blockchain: The New Technology of Trust
PPTX
BLOCKCHAIN
PPTX
Write Smart Contracts with Truffle Framework
Smart Contract & Ethereum
Introduction To Solidity
Introduction to Blockchain and Smart Contracts
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Blockchain consensus algorithms
Blockchain: The New Technology of Trust
BLOCKCHAIN
Write Smart Contracts with Truffle Framework

What's hot (20)

PDF
Ethereum Solidity Fundamentals
PPTX
Introduction to Blockchain
PPTX
Blockchain Technology
PDF
Blockchain
PDF
Bitcoin and Ethereum
PDF
The Lightning Network - A gentle introduction
PPTX
Introduction to Solidity and Smart Contract Development (9).pptx
PPTX
Blockchain
KEY
Introduction to bitcoin
PDF
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
PPTX
Overview of Blockchain Consensus Mechanisms
PPTX
Rego University: Hidden Automation & Gel Scripting, CA PPM (CA Clarity PPM)
PDF
Blockchain: The New Technology and Its Applications for Libraries
PPTX
Solidity programming Language for beginners
PPTX
for loop in java
PDF
Blockchain Technology Fundamentals
PDF
Blockchain and Decentralization
PDF
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
PPTX
Consensus Algorithms.pptx
Ethereum Solidity Fundamentals
Introduction to Blockchain
Blockchain Technology
Blockchain
Bitcoin and Ethereum
The Lightning Network - A gentle introduction
Introduction to Solidity and Smart Contract Development (9).pptx
Blockchain
Introduction to bitcoin
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Overview of Blockchain Consensus Mechanisms
Rego University: Hidden Automation & Gel Scripting, CA PPM (CA Clarity PPM)
Blockchain: The New Technology and Its Applications for Libraries
Solidity programming Language for beginners
for loop in java
Blockchain Technology Fundamentals
Blockchain and Decentralization
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Consensus Algorithms.pptx
Ad

More from Tutorials Diary (11)

PPTX
Solidity Tutorials- Difference between msg.sender and tx.origin
PDF
Solidity Tutorials- Libraries in solidity
PDF
Solidity Tutorials- Transer/Send ether- Transfer(), send(), call() function i...
PDF
Solidity Tutorials- Function call in solidity
PDF
Constructor in solidity
PDF
Inheritance in solidity
PDF
Interface in solidity
PDF
Abstract contract In Solidity
PDF
Solidity low level logging
PDF
Blockchain Introduction
PDF
Blockchain Webinar
Solidity Tutorials- Difference between msg.sender and tx.origin
Solidity Tutorials- Libraries in solidity
Solidity Tutorials- Transer/Send ether- Transfer(), send(), call() function i...
Solidity Tutorials- Function call in solidity
Constructor in solidity
Inheritance in solidity
Interface in solidity
Abstract contract In Solidity
Solidity low level logging
Blockchain Introduction
Blockchain Webinar
Ad

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PPTX
Spectroscopy.pptx food analysis technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Digital-Transformation-Roadmap-for-Companies.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
Spectroscopy.pptx food analysis technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation

Solidity- Error Handling

  • 1. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y S O L I D I T Y E R R O R H A N D L I N G
  • 2. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com Error Handling How to do error handling in solidity
  • 3. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com Error Handling require assert revert throw
  • 4. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com require Here we check the conditions and revert the state in case condition does not met. This is most commonly used in solidity for error handling This does not consume any gas Syntax require(condition, errorMessage) Example require(newBalance > minimumBalance, "Your do not have minimum balance in your account")
  • 5. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com assert Prevent anything really bad from happening. This does consume all the gas and revert the state Syntax assert(condition) Example assert(balance %2 == 0)
  • 6. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com revert This revert the state along with error message Syntax revert("failure reason") Example revert("you do not have sufficient balance" )
  • 7. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com throw This is used to revert the state but this is depreciated now Syntax throw Example throw;