Solidity 在 0.8.4 版本中推出了 error 关键字,可以像 event 那样定义一个错误类型,官方文档提到使用 error 关键字可以节省 gas,并且可以在错误信息中添加参数:Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them...