66 异常处理
throw 中断正常执行;匹配的 catch Exception error 处理异常后,程序继续执行下一条语句。
norm
import std.core.Exception
Void fail() {
throw Exception(message: "unavailable")
}
main() {
try {
fail()
} catch Exception error {
printLine(error.message)
}
printLine("continued")
}预期输出:
text
unavailable
continued动手试试:删除 catch,观察未处理异常的行为。
精确规则:参考。