Re: Should a Method set NSError* to nil when No Error?
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