• 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
Should a Method set NSError* to nil when No Error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Should a Method set NSError* to nil when No Error?


  • Subject: Should a Method set NSError* to nil when No Error?
  • From: Jerry Krinock <email@hidden>
  • Date: Sat, 19 Apr 2008 09:46:41 -0700

I often write methods that take an (NSError**)error_p argument. In the documentation of Apple methods that do this, I read that the NSError** will be set if there ^is^ an error, but most do not specify what will happen if there is ^not^.

When there is no error, if I'm provided a non-NULL error_p, I like to set *error_p to nil before returning, so that the invoker can use (*error_p==nil) after my method returns to check for no error. Now, Chris Hanson wrote once that this check is not a recommended idiom, and that, to indicate no error, a method should set its return value to YES. But even when I return YES or NO as he recommends, I don't like the idea of leaving the error_p undefined, so I pre-set *error_p to nil at the beginning of my methods.

Now I wonder if someone might expect NSError** to remain untouched, maybe preserving some previous error. Usually you bail out immediately and would not invoke any more methods after an error occurs, but does anyone know a good reason to not set *error_p = nil in case of no error?

_______________________________________________

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


  • Follow-Ups:
    • Re: Should a Method set NSError* to nil when No Error?
      • From: Uli Kusterer <email@hidden>
    • Re: Should a Method set NSError* to nil when No Error?
      • From: Bill Bumgarner <email@hidden>
  • Prev by Date: Get list of possible applications
  • Next by Date: Re: Get list of possible applications
  • Previous by thread: Re: Get list of possible applications
  • Next by thread: Re: Should a Method set NSError* to nil when No Error?
  • Index(es):
    • Date
    • Thread