1
我應該從函數拋出一個異常方便的功能它內部調用:從調用函數傳遞誤差達是雨燕2.1
public func save() throws -> Bool {
do {
return try self.save(self.filePath)
} catch {
// How to throw error from the function save(filePath:) ??
}
return false
}
public func save(filePath: String) throws -> Bool {
do {
let jsonData = try NSJSONSerialization.dataWithJSONObject(self.jsoNObject, options: NSJSONWritingOptions.PrettyPrinted)
return jsonData.writeToFile(self.filePath, atomically: true)
}catch {
throw PersistedError.NSJSONSerializationError
return false
}
}
如何通過或拋出由save(filePath: String)
在save()
拋出的錯誤功能?