Re: odd behavior with NSError?
Re: odd behavior with NSError?
- Subject: Re: odd behavior with NSError?
- From: Ben Trumbull <email@hidden>
- Date: Thu, 15 Oct 2009 23:45:31 -0700
(response is pedantic for the purposes of the archive :)
even more better flaming pedanticism!
On Oct 15, 2009, at 10:41 PM, Nathan Vander Wilt wrote:
Ouch. So the following pattern is incorrect?
Yes; it is incorrect.
NSError* internalError = nil;
(void)[foo somethingReturningBool:bar error:&internalError];
if (internalError) {
// ...
}
Specifically, assuming anything about the value of 'internalError'
without first determining the return value of -
somethingReturningBool:error: returned a value indicating an error
(typically NO/0/nil/NULL) is an error.
The specific issue is failing to check the return value of the method
before touching the internalError value. You MUST check it.
However, the documentation also encourages not assigning nil to local
NSError* declarations. Not initializing locals is imho,
professionally, realistically, and morally wrong. It's just a bug
waiting to happen. And you have to know it is, just looking at it.
Whatever might have been saved / gained by not initializing them was
wasted, for all of time, the first time I had to debug the segfault.
Which I did, like an idiot, a long time ago.
Let me just say I really especially appreciated the time spent
debugging other people not initializing their locals. It wasn't
visions of sugar plums.
Other people have different perspectives on local variable
initialization. Wrong perspectives, but different. Fortunately now,
they waste their arguments upon the merciless <http://llvm.org/img/DragonFull.png
>
- Ben
_______________________________________________
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