On 2008 Apr, 19, at 11:24, Bill Bumgarner wrote:

If there is no error -- if the return value is set and valid -- then the behavior regarding the (NSError**) argument is undefined.

Agreed, although not the way I would have designed it.

Any caller relying upon the value to be...unchanged...is implemented incorrectly.


Thank you!  That's what I wanted some support for.

As such, you are certainly free to do something like:
...

    *anError = [NSError ...];  // Whoops
...


Except that the above line will cause a crash if the invoker was not interested in the details and passed anError = NULL.

Forgetting to test that anError != NULL before assigning it is a really easy mistake to make (oh, especially when coding in Mail, I know...but I've done it in actual work!) Also, it is a mistake that won't show up in testing unless the test suite covers the triggering error. Ouch.

So, as of 2 hours ago I'm using the following macro at the beginning of all my methods that take an NSError** argument:

#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.

As the caller of your own method, do not rely on *anError being set to nil. Doing so creates an impedance mismatch with the rest of Cocoa's behaviors and, thus, is simply asking for trouble.

I agree with that.  Thanks again, Bill.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to