如何在SUI区块链中定义移动错误类型
试图理解我们应该设置错误
in sui blockchain 智能合约。
从提供的示例中,似乎我们应该根据不同的预期错误来定义常数,即市场智能合约定义了两个错误:
// For when amount paid does not match the expected.
const EAmountIncorrect: u64 = 0;
// For when someone tries to delist without ownership.
const ENotOwner: u64 = 1;
问题:
- 命名错误常数的惯用移动语言的方式, 从
e
字符开始,然后是骆驼盒? - 如果开发人员将相同的数字分配给两个或多个错误怎么办?
Trying to understand the idiomatic way we should set Errors
in Sui blockchain smart contracts.
From the provided examples it seems that we should define constants per different expected error i.e. in Marketplace smart contract two errors are defined:
// For when amount paid does not match the expected.
const EAmountIncorrect: u64 = 0;
// For when someone tries to delist without ownership.
const ENotOwner: u64 = 1;
Questions:
- what is the idiomatic Move-language way to name the error constants,
starting with theE
character then camel case? - what if a dev assigns the same number to two or more errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正确的。
移动模块的作者可以免费将相同的数字分配给多个错误,因为它们与常规常数没有什么不同。这取决于移动模块的消费者如何解释从移动VM返回的错误代码。 SUI移动本身并不禁止两个错误常数具有相同的值。但是,我们可能会为SUI STDLIB添加一个模块,以定义将来的错误标准。
That's right.
The author of a Move module is free to assign the same number to more than one errors since they are no different from regular constants. It is up to the consumer of the Move module how to interpret the error codes returned from the Move VM. Sui Move itself doesn't prohibit two error constants from having the same value. We may, however, add a module to Sui stdlib defining an error standard in the future.