示例工程 13-error-handling

13-error-handling/Diagnostics/ClosureNotThrowing.swift

swift · 0.3 KB

// 故意编译失败:可抛错的闭包不能赋给非抛错函数类型。
// 复现:swiftc Diagnostics/ClosureNotThrowing.swift
enum E: Error { case x }
 
func load() throws -> Int {
    throw E.x
}
 
let handler: () -> Int = { try load() }
print(handler())