> Perhaps there is already a policy on when each is to be used. If so, please > enlighten me. :)
There is a policy in Cocoa. I'm pretty sure it's documented, but I didn't find it laid out just now.. Exceptions are for things that just shouldn't happen, or that are essentially unrecoverable. Throw an exception if the programmer using your API made a mistake and passed parameters that it isn't in your contract to handle. People are not expected to be catching exceptions. NSApplication catches them up at the top of the event loop, and will log. NSError is for errors of the sort you'd want to tell the user about. They're supposed to be directly presentable via -[NSApplication presentError:] and friends. If the thing that went wrong is internal and you expect the programmer to handle it, NSError isn't appropriate. (A piece of calling code that has more user-centric information about what went wrong than the one that generated the NSError may and should replace the NSError with one that is more appropriate, though.) For APIs that programmers may expect to fail and handle without getting the user involved, Cocoa usually just returns a BOOL to say "nope, didn't work", or returns nil or somesuch. I think there are a few APIs that that give a 'reason' why something happened. -Ken On Tue, Oct 28, 2008 at 12:58 AM, Colin Cornaby <[EMAIL PROTECTED]> wrote: > I'm writing an API to communicate with a web service, and I was just > wondering what the thinking is on exceptions vs. functions returning an > NSError in some way. Basically I'm wondering what people's opinions are on a > function throwing an exception on failure, vs returning an NSError object. > > Perhaps there is already a policy on when each is to be used. If so, please > enlighten me. :) > > Thanks, > Colin > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com > > This email sent to [EMAIL PROTECTED] > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]