Skip to content

Instantly share code, notes, and snippets.

@critesjosh
Last active March 14, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save critesjosh/87f9ff1e432216fa6f6ef1b5551efbf2 to your computer and use it in GitHub Desktop.
Save critesjosh/87f9ff1e432216fa6f6ef1b5551efbf2 to your computer and use it in GitHub Desktop.
How to correctly throw errors in Solidity
pragma solidity ^0.4.0;
contract ThrowErrorExample {
bool isTrue = true;
uint num = 1;
//Bad code, do not emulate
function silentFail() public view returns (uint){
if(isTrue != true){
return num;
}
}
function throwsError() public view returns (uint){
require(isTrue != true);
return num;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment