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

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.


  • Prev by Date: Re: Setting a NSScrollView's Scroll Amount
  • Next by Date: Re: Problem saving movie
  • Previous by thread: Re: returning nil on initialization
  • Next by thread: Re: Cocoa Cleanup
  • Index(es):
    • Date
    • Thread