Errors thrown from here are not handled for do { } catch in Swift 2.0

后端 未结 2 632
渐次进展
渐次进展 2021-02-03 21:34

After i update swift 2.0 i got an error with do { try } catch like an image below.

How can i fix this? Thanks!

2条回答
  •  囚心锁ツ
    2021-02-03 21:55

    The error is telling you that the enclosing catch is not exhaustive. This is because the auto-generated catch block is only catching NSError objects, and the compiler can't tell whether some other ErrorType will be thrown.

    If you're sure no other errors will be thrown, you can add another default catch block:

    do {
        objects = try managedObjectContext?.executeFetchRequest(request)
    } catch let error1 as NSError {
        error = error1
        objects = nil
    } catch {
        // Catch any other errors 
    }
    

提交回复
热议问题