returning nil on initialization
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.