I'm reviewing some errors, and I notice that some of them occur in JSONEncoder, where there's a 'try' and I have a 'do/catch' to catch the exception.
However, these errors don't reach the 'catch,' causing the app to crash.
My question is whether there's any difference between using a 'try?' that returns nil or using a 'catch'? Could it be that the error caught by 'catch' is different from simply returning nil? Or, beneath all this, is it exactly the same?
I'm not understanding why some errors aren't being handled, leading to the app's termination.
Thanks in advance. Regards.
I think the issue is that Swift can catch NSErrors thrown from Obj-C but JSONEncoder can also throw an NSException and that will crash your app even if you use try/catch when calling it from Swift.
There are workarounds, but none of them are great. I think a google search can give a better explanation than I can.
No difference in which errors can be propagated. If your app is crashing despite your code being in a do…catch block then it is not due to a recoverable error in that code.