Can any one tell me what is the best to handle exception in iOS (Objective C)?
I have the following two approaches:
- Use try/catch block.
- Do proper data handing for all model class.
What do you suggest?
Can any one tell me what is the best to handle exception in iOS (Objective C)?
I have the following two approaches:
What do you suggest?
Exceptions in Objective are only meant to be used for programming errors where there is no recovery (the app will terminate immediately).
Exception are not designed to be used for program control flow in Objective-C. Check for all possible errors and handle them at that point.
Further, there is no cleanup on catches across stack frames so full recovery is generally not possible.
On iOS, you should fix whatever is causing the exception. NSError is for errors that are expected (e.g. Backend returns invalid or not data). Exceptions are usy programming errors and should be fixed. Avoid try/catch, except when it is explicitly stated you should use it (e.g. Subclassing NSOperation).