假设这是我们从模型中删除对象的函数:
func delete(indexPath: IndexPath) {
let managedObject = self.fetchedResultsController.object(at: indexPath)
self.managedObjectContext.delete(managedObject)
do {
// Save changes
try self.managedObjectContext.save()
// Cancel the notification
let center = UNUserNotificationCenter.current()
center.removeDeliveredNotifications(withIdentifiers: [managedObject.uuid!])
center.removePendingNotificationRequests(withIdentifiers: [managedObject.uuid!])
// Reload tableView
self.tableView.reloadData()
} catch {
let alertController = UIAlertController.init(title: "Error", message: "We are sorry! Unknown error occured...", preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "Close", style: .default, handler: { (action) in
// Completion handler
}))
self.present(alertController, animated: true, completion: {
// Completion block
})
}
}
问题:
如果抛出错误,则执行转移到catch
子句。那很好。但是语句(其余代码,取消通知和重新加载 tableView)会发生什么?这些语句仍然是可执行的还是简单地忽略?