solidity基础-异常

assert

contract ErrorTest {

    uint256 public balance;

    function deposit(uint256 _amount) public{
        balance = balance + _amount;
    }

    function withdraw(uint256 _amount) public{
        uint256 oldBalance = balance;
        balance = balance - _amount;
        assert(balance > oldBalance );
    }

}

部署存入25, 可以看到balance 有 25

   

 

 再提取 100

      

 输出报错

  

 

posted @ 2022-05-05 08:54  apeNote  阅读(10)  评论(0编辑  收藏  举报