-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.sol
37 lines (29 loc) · 884 Bytes
/
errors.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract Errors {
function Test_require(uint _i) external pure {
require(_i > 10,"i < 10");
}
function TestRevert(uint _x) external pure {
if(_x > 10){
revert("_x > 10");
}
}
uint public addr = 123;
function testAssert() external view {
//assert is used when the condition should always be true
assert(addr==123);
}
//this fn will return false as addr shouldn't be changed
function foo(uint _i) external{
addr+=1;
require(_i <= 10);
//updates to the state variable will fail as require fn gets false
}
error MyError(address caller, uint i);
function flee(uint _i) public view {
if(_i > 10){
revert MyError(msg.sender, _i);
}
}
}