I'm new to Objective-C world. What I have noticed while studying some iOS/Mac apps is that try -catch is rarely used, if used at all. For example in Java it is used almost all the time. Why isn't it so common in Objective-C ?
-
possible duplicate of [What’s the rationale behind the Cocoa exception policy - or why use exceptions only for programmer errors?](http://stackoverflow.com/questions/3811620/whats-the-rationale-behind-the-cocoa-exception-policy-or-why-use-exceptions-o) – jscs Mar 15 '12 at 18:58
-
And a _great_ pair of answers by zneak and bbum here: http://stackoverflow.com/questions/4648952/objective-c-exceptions – jscs Mar 15 '12 at 19:00
2 Answers
Exceptions in Objective-C are generally to be used for truly exceptional circumstances and almost always programmer error. To convey a recoverable error use the NSError** pattern.

- 28,598
- 2
- 97
- 90
There are a lot of SDK methods that take an NSError**
parameter and return BOOL
. To indicate an error they return false and feed an error back through the error parameter to communicate info.
Exceptions are used, but generally for cases in which there is some failure at the runtime level - e.g. some object can't handle a selector. Although it may seem contrary to what I just wrote, exceptions tend to indicate an error in design rather than a runtime error.
The NSError**
idiom is all you need for things such as failed URL connections, data conversions, etc, where an error condition exists but a program really shouldn't be killed outright.
Start reading: Error Handling Programming Guide

- 9,803
- 7
- 50
- 87