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.
why is this. I have no idea. how to solve this. hope your help.
The deleteObject
method doesn't throw. Remove the Do-Catch
block and the warning will go away. The warning seems pretty self explanatory.
Make sure that the method that you are invoking after try
throws.
Example:
func someThrowingFunction() throws -> Int {
// ...
}
let x = try? someThrowingFunction()
let y: Int?
do {
y = try someThrowingFunction()
} catch {
y = nil
}
more information about that here: ErrorHandling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With