let s = try String(contentsOfFile: f, encoding: NSUTF8StringEncoding)
// ... if successful, do something with s ...
} catch NSCocoaError.FileReadNoSuchFileError {
print("no such file")
} catch {
print(error)
}
参见
Objective-C
中的
FoundationError.h
头文件来了解关于
Cocoa
内建标准错误域 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.