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

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


  • Subject: Re: Should a Method set NSError* to nil when No Error?
  • From: Ali Ozer <email@hidden>
  • Date: Sat, 19 Apr 2008 15:11:36 -0700

#define SSYInitErrorP(_error_p) NSError* dummyError ; \
if (_error_p == NULL) { \
   _error_p = &dummyError ; \
} \
* _error_p = nil ;

I use it like this, with an (NSError**)error_p:

   SSYInitErrorP(error_p)

Besides setting *error_p to nil, which we agree is not necessary but I "just like", it also assigns error_p to a dummy NSError* if NULL was passed in, avoiding latent crashes.

One of the benefits of checking for (errorPtr == NULL) is that you avoid creating the error object (along with its user info and such) if the caller was not interested in the value.


So why not a macro that assigns the value instead:

   #define AssignError(_error_p, err) if (_error_p) {*_error_p = err;}

BTW, Cocoa methods in general do not set the pointer to nil in case of no error, but as Bill said, we haven't documented that behavior.

Ali

_______________________________________________

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


References: 
 >Should a Method set NSError* to nil when No Error? (From: Jerry Krinock <email@hidden>)
 >Re: Should a Method set NSError* to nil when No Error? (From: Bill Bumgarner <email@hidden>)
 >Re: Should a Method set NSError* to nil when No Error? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Simulating menu bar blink in Cocoa
  • Next by Date: Re: presentError:
  • Previous by thread: Re: Should a Method set NSError* to nil when No Error?
  • Next by thread: Re: Should a Method set NSError* to nil when No Error?
  • Index(es):
    • Date
    • Thread