• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: -(id)init methods, NSExceptions, and returning nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -(id)init methods, NSExceptions, and returning nil


  • Subject: Re: -(id)init methods, NSExceptions, and returning nil
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 27 Jun 2011 09:51:47 -0500

On 27-Jun-2011, at 9:22 PM, William Squires wrote:

> 2) Isn't the prevailing paradigm to raise an NSException if something goes wrong?


No.  In Cocoa, exceptions are used to indicate programmer error, not runtime failure.  In general, Cocoa isn't exception safe, so if an exception occurs, your app should do its best to gracefully shut down, save data (without overwriting known-good data, since you can't be sure the app is in a good state), with an explanation to the user.

> or is 'init'ing a special case?


-init isn't special with respect to the above convention regarding exceptions, but it does have its own conventions.  Among those is that failure is indicated by returning nil.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >-(id)init methods, NSExceptions, and returning nil (From: William Squires <email@hidden>)
 >Re: -(id)init methods, NSExceptions, and returning nil (From: Roland King <email@hidden>)

  • Prev by Date: Re: -(id)init methods, NSExceptions, and returning nil
  • Next by Date: Re: -(id)init methods, NSExceptions, and returning nil
  • Previous by thread: Re: -(id)init methods, NSExceptions, and returning nil
  • Next by thread: Re: -(id)init methods, NSExceptions, and returning nil
  • Index(es):
    • Date
    • Thread