【问题标题】:'no calls to throwing functions occur within 'try' expression [warning] in swift 3'在swift 3中的'try'表达式[警告]中没有调用抛出函数
【发布时间】:2016-11-23 02:40:57
【问题描述】:

我试图从核心数据中删除和反对,我在 try catch 中尝试了它,如下所示。

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

上面写着'no calls to throwing functions occur within 'try' expression'catch block is unreachable because no errors are throw in 'do' block。下图给你更多的想法。

这是为什么。我不知道。如何解决这个问题。希望您的帮助。

【问题讨论】:

  • 错误信息告诉你所有你需要知道的...

标签: ios core-data swift3 try-catch warnings


【解决方案1】:

deleteObject 方法不会抛出。删除Do-Catch 块,警告就会消失。该警告似乎很容易解释。

【讨论】:

    【解决方案2】:

    确保您在try 之后调用的方法throws

    例子:

    func someThrowingFunction() throws -> Int {
        // ...
    }
    
    let x = try? someThrowingFunction()
    
    let y: Int?
    do {
        y = try someThrowingFunction()
    } catch {
        y = nil
    }
    

    更多信息请点击此处:ErrorHandling

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 2023-03-28
      • 2014-01-28
      • 1970-01-01
      • 2021-05-03
      • 2018-01-21
      相关资源
      最近更新 更多