• 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
returning nil on initialization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

returning nil on initialization


  • Subject: returning nil on initialization
  • From: Chaz McGarvey <email@hidden>
  • Date: Sun, 28 Mar 2004 14:13:41 -0700

Hello:

I've always been in the habit of releasing and returning nil whenever initialization of an object fails. I'm not sure where I picked this up or if it's even common (I think I just picked it up from some Cocoa book somewhere along the way), but I'm wondering if this is a good thing to do.

I ask because I recently experienced a problem because of this. It seems that the nib loading code doesn't check for nil views. I discovered this when I set up a subclass of an NSOpenGLView to return nil while initializing if the pixel format is invalid. The nib loading code attempted to store the view in an array and the view was nil; obviously the inserting of nil into the array caused an exception.

So my question: is returning nil if the initialize fails generally a bad thing to do, design-wise if nothing else? It just seems convenient to me, but I'm no guru.

Chaz McGarvey
http://www.brokenzipper.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: returning nil on initialization
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: NSScrollView how to scroll to top
  • Next by Date: Re: NSScrollView how to scroll to top
  • Previous by thread: Re: Shared file between users
  • Next by thread: Re: returning nil on initialization
  • Index(es):
    • Date
    • Thread