Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exception handling in iphone?

what is the syntax for handle the exceptions in iphone sdk? how to handle the exceptions in iphone. what documentation to know more about? tutorial, sample code are most wanted and thankful.

like image 757
Praveen Avatar asked Dec 28 '22 18:12

Praveen


1 Answers

Exceptions in Objective-C are quite a contentious issue, even Apple themselves discourage you from using them unless absolutely necessary.

My first question would be what do you want to achieve from the exception handling? If you're looking from a Java perspective and how exceptions are so tightly integrated in that language for handling errors (i.e. flow control) then I think it's unadvisable to use objective-c exceptions for this purpose, you need to use NSError and handle errors that way.

This is a snippet from Apples documentation: -

Exceptions are resource-intensive in Objective-C. You should not use exceptions for general flow-control, or simply to signify errors. Instead you should use the return value of a method or function to indicate that an error has occurred, and provide information about the problem in an error object. For more information, see Error Handling Programming Guide For Cocoa.

like image 156
djhworld Avatar answered Dec 31 '22 09:12

djhworld