Created
April 9, 2023 18:12
-
-
Save CJ42/657e6b917b668c735a44ae0f3bd329b0 to your computer and use it in GitHub Desktop.
Code snippet to show the different type of Solidity errors when debugging their selector (first 4 bytes of keccak256 hash of the error type string)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
contract SolidityErrors { | |
error InsufficientBalance( | |
uint256 amount, | |
uint256 balance | |
); | |
function testRevertErrorEmpty() | |
public | |
pure | |
{ | |
revert(); | |
} | |
function testRevertError() | |
public | |
pure | |
{ | |
revert("something went wrong!"); | |
} | |
function testPanicError(uint256 a) | |
public | |
pure | |
returns (uint256) | |
{ | |
return 10 / a; | |
} | |
function testCustomError(uint256 amount) | |
public | |
view | |
{ | |
revert InsufficientBalance( | |
amount, | |
address(this).balance | |
); | |
} | |
function testInvalid() | |
public | |
pure | |
{ | |
assembly { | |
invalid() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment