--- On Tue, 10/28/08, 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. :)
>From the conceptual docs on Cocoa exceptions:
"IMPORTANT: You should reserve the use of exceptions for programming or
unexpected runtime errors such as out-of-bounds collection access, attempts to
mutate immutable objects, sending an invalid message, and losing the connection
to the window server. You usually take care of these sorts of errors with
exceptions when an application is being created rather than at runtime.
...
Instead of exceptions, error objects (NSError) and the Cocoa error-delivery
mechanism are the recommended way to communicate expected errors in Cocoa
applications."
My interpretation of this is that exceptions are meant to be a slightly nicer
version of a crash -- something that should only come about through a bug in
the program. If it's merely an error that might occur in the normal operation
of the app (like reading a malformed file), it should be an NSError rather than
an exception. This seems to be the policy that's generally employed in the
Cocoa frameworks too.
Cheers,
Chuck
_______________________________________________
Cocoa-dev mailing list ([email protected])
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]