Error handling in solidity

Error handling in solidity

Error handling is always a very important topic in any language, sample applies to solidity as well. Still it does not have all the features like handling of error and expected to be there in upcoming releases but there are few concepts that each developer need to understand before they deep dive in development using solidity.

There are four main concepts in solidity error handling.

  • require
  • assert
  • revert
  • throw


  • 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")



  • Prevent anything really bad from happening.
  • This does consume all the gas and revert the state
Syntax assert(condition)

Example assert(balance {1d6e369f27b3b55fac77a13f30e13d2b04ce9713b9295394d4a423074fd2099f}2 == 0)



  • This revert the state along with error message
Syntax revert("failure reason")

Example revert("you do not have sufficient balance" )



  • This is used to revert the state but this is depreciated now
Syntax throw

Example throw;

No Comments

Give a comment

Inquire Now
close slider