Re: returning nil on initialization
Re: returning nil on initialization
- Subject: Re: returning nil on initialization
- From: "Mathieu Godart" <email@hidden>
- Date: Mon, 29 Mar 2004 10:28:07 +0200
>
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.
When a message is sent to an object that doesn't exist, an exception is
raised. But when the same message is sent to an object equal to nil, you
don't have this problem.
The other interesting thing with returning nil is that you can check the
value of the return function if the allocation is likely to fail.
For me, when the init is not likely to fail, returning nil is a good way to
handle a problem of memory lack or ressource problem... But, when your init
has more chance to fail (for example: tou OGL problem, a missing file...),
you have to handle this in a more "reliable" way (displaying an error
pannel, raising an exception, returning an error code, checking the return
of the method...).
In your case, the failure of the init of the NSOpenGLView may cause heavy
problems to your app. Therefore, you'll have to check that the init doesn't
return nil (if it does, stop your app or do something) or display something
during the init method.
I hope this helps,
Mathieu
_______________________________________________
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.