0

Maybe I'm missing something, but the Swift error handling mechanisms seem to me to presume that you can anticipate every error that might occur. We're all human, so this doesn't seem realistic. I'd like to have the ability to react (e.g. by giving the user an indication of the error on-screen so they can contact the help desk) when an error that I've not detected and thrown occurs. I've seen here that I can catch all NSExceptions, but not Swift errors - the example in that thread is that I wouldn't catch

let arr = [1, 2, 3]
let elem = arr[4]

so, am I just stuck with living with the possibility of crashes in situations like this when I've not anticipated the error?

Community
  • 1
  • 1
Jon Cook
  • 127
  • 1
  • 11
  • 1
    See also http://stackoverflow.com/questions/38737880/uncaught-error-exception-handling-in-swift, which has some links explaining the rationale not to catch all unforeseen errors in Swift. – Martin R Sep 04 '16 at 10:07
  • 1
    I'd prefer unit testing and beta testing over customer testing ;-) – vadian Sep 04 '16 at 10:09
  • Test Driven Development solves problems like this. – JFAP Sep 04 '16 at 10:28
  • Oops - sorry I missed that existing question. I must say, of course unit testing/beta testing is essential (I saw your ;-) vadian - no hard feelings :>) - and TDD is wonderful... but a last resort when something slips through the cracks is useful for support. Anyway - I now understand the situation and the rationale - so thanks! – Jon Cook Sep 04 '16 at 11:02

0 Answers0