Search code examples
ioscore-dataswift3try-catchwarnings

'no calls to throwing functions occur within 'try' expression [warning] in swift 3


I'm trying to delete an object from core data and I tried it within try catch as below.

do {
   try self.managedContext.deleteObject(self.productList[indexPath.row])
} catch let error as NSError {
        print("something wrong with the delete : \(error.userInfo)")
}

it say 'no calls to throwing functions occur within 'try' expression and 'catch block is unreachable because no errors are throw in 'do' block. following image give you more idea.

enter image description here

why is this. I have no idea. how to solve this. hope your help.


Solution

  • The deleteObject method doesn't throw. Remove the Do-Catch block and the warning will go away.