Identification of personalized errors in Ethereum: A address guide.cal
In solidity, address. Howver, it can also be used to transfer Walue between accounts or trigger preferences, will receive the following foys. When using
address. In this article, we will explore how to detect and diagnose Wen personalized errors using address.
What are personalized errors?
Custom appears with unaccepted intelligent information, invalid calculations or other IC. These errors can be caused by different factors, which: as:
- Incorrect use of Ethereum's functions (egBalanceof
)
- Incompatible data of data
- Unparalleled exceptions in solidity
How to identify personalized errors withAddress.Cal
Useaddress. In the exterior schools, it will be time for execution to complement and errors. To identify the errors using address.
- Monitor the executive time of the contract : ll. This can help you estimate the probability of a process error.
20 kks). If it is not an error, it can be indicated a suitable error.
- Inspect the return value of the contract
: Check the contractor's return to see to the one, if there are unexpected errors or results. You can access this information use "solidity-coverage" or other analysis.
Code for example: Detection of personalized errors withoutaddress.Cal
Let's take a simple one to illustrate how you can detinate errors that useaddress. We will create two contract functions, balancece and add, return different values based on the entry data.
Solidity
Pragma solidity ^0.8.0;
Customerror contract {
builder () {
EMI event ();
}
BALANCEOF function (_owner address) A public view returns (UINT256) {
)
Request (_owner! = 0, “invalid owner”);
Return _owner.Balance;
}
ADD function (uint256 _amouunt) a public view returns (UNT256) {
)
Request (msg.value> = 0 && msg.value <= 10 ** 18, "Invalid ammunt");
return _amouunt + msg.value;
}
}
`
In this example, we defined two contract functions, which threw Jenktom errors. The "Balanceof" function returns the Ethereum Eddress balance.
Wen calladdress.calfrom another contractor without an invalid argument or unexpected information:
Solidity
Test Contract {
Test function () public {
Customcontractor Customerror = New Customeror ();
Triy {
CustomContrate.Balanceof (0); // should throw an error but we don’t expect it.
Customcontract.add (1);
} Catch (error) {
requires (error.message == “Invalid error”);
}
}
}
`
In this example, if the "Balanceof" function is called Wi-0 Ethereum Eddress or an invalid invalid invalid invalid invalid Walue, aCustomeror wil ben. The “addition” function will also throw an invalid argument.
Conclusion
*
To identify and diagnose errors using `address.