出现错误停止执行
可以用 error 函数停止执行。比如:
foo := if "hello" == "goodbye" {
  "xyz"
} else if "a" == "b" {
  "abc"
} else {
  error("123")
}
在运行时产生以下错误:
error: Call to function `error` failed: 123
   |
16 |   error("123")
                    Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
可以用 error 函数停止执行。比如:
foo := if "hello" == "goodbye" {
  "xyz"
} else if "a" == "b" {
  "abc"
} else {
  error("123")
}
在运行时产生以下错误:
error: Call to function `error` failed: 123
   |
16 |   error("123")