• 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: exception in init
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exception in init


  • Subject: Re: exception in init
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 04 Apr 2012 08:53:29 -0700

On Apr 4, 2012, at 4:38 AM, Ariel Feinerman wrote:

> I think the question was asked and answered but I cannot see a clearance
> what is the right way to write init in the cases the arguments are nil or
> wrong?
> Returning a nil or raising an exception?

If the argument values are literally wrong — if it's illegal to pass those values — then you raise an exception. The idea is that this must represent a bug in the program, so you abort what's going on to keep it from going any further.

If the situation could occur in a valid program, but should not create a new object, then you can release self and return nil. In this case it's often good to return an NSError or other error information to the caller, i.e. as an 'out' parameter.

—Jens
_______________________________________________

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: 
 >exception in init (From: Ariel Feinerman <email@hidden>)

  • Prev by Date: Re: exception in init
  • Next by Date: Re: exception in init
  • Previous by thread: Re: exception in init
  • Next by thread: Re: exception in init
  • Index(es):
    • Date
    • Thread