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

13,992

Solution 1

The deleteObject method doesn't throw. Remove the Do-Catch block and the warning will go away. The warning seems pretty self explanatory.

Solution 2

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

Share:
13,992

Related videos on Youtube

caldera.sac
Author by

caldera.sac

Updated on June 04, 2022

Comments

  • caldera.sac
    caldera.sac almost 2 years

    I' trying to delete and object from core data and I tried it within try catch like 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.

    • Alexander
      Alexander over 7 years
      The error message tells you literally everything you need to know...