E4127#
类型不是错误类型。
MoonBit only allow error types (defined with type!
keyword) to appear after
the exclamation mark (!
) in the return type of a function.
错误示例#
pub fn may_raise_error() -> Unit!String {
// ^~~~~~
// Error: Type String is not an error type.
raise "Failed" // Error: Type String is not an error type.
}
建议#
可以将希望引发错误的类型包装在错误类型中:
type! StringError String
pub fn may_raise_error() -> Unit!StringError {
raise StringError("Failed")
}