This article is Part II of the “All About Errors” sub-series.
After looking at Compile Time errors in Part I (errors generated by the Solidity compiler), we will now look in Part II at runtime errors (errors generated at the time you interact with a contract deployed on a live network).
As we will see, 4 main types of errors can be generated in Solidity:
Error(string), Panic(uint256), custom
invalid. We will cover the rules and semantics of each of them in this article. Finally, we will have a quick glance at some potential predictions for the new error types that might be added to the Solidity programming language.
Table of content
- Common examples of errors in Solidity
- Types of Solidity errors
- Panic Error - Example
- Panic(uint256) error codes
- Custom Errors
- How to define custom errors?
- Why using custom errors over string errors?
- Named parameters for custom errors
- Natspec comments for custom errors
- Custom Errors are part of the ABI
- Future Type of Errors in Solidity
Common examples of errors in Solidity
Many scenarios exist where a runtime error could occur among the Solidity code of a contract.
Some of the standard runtime errors related to Solidity include:
require()is called with the arguments which result as false.
- When creating a contract using the
newkeyword fails, and the process does not end properly.
- When a codeless (
address.code.length) contract is targeted to an external function. (be aware of the
isContract()culprit when it is running through a
- When ethers (=
msg.value) is sent while calling a public getter (
puremethod from a contract.
- when ethers (=
msg.value) are sent to a function in a contract that is not marked as
- When a condition in an
- When a zero-initialised variable of
functiontype is called.
- When a large or negative value is converted to an
- When accessing an array in an index which is too big or…