FROM : Jerry Krinock
DATE : Sat Apr 19 18:46:41 2008
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?
DATE : Sat Apr 19 18:46:41 2008
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?
| Related mails | Author | Date |
|---|---|---|
| Jerry Krinock | Apr 19, 18:46 | |
| Bill Bumgarner | Apr 19, 20:24 | |
| Jerry Krinock | Apr 19, 22:10 | |
| Ali Ozer | Apr 20, 00:11 | |
| Uli Kusterer | Apr 20, 01:03 | |
| Jean-Daniel Dupas | Apr 20, 11:45 | |
| Uli Kusterer | Apr 20, 16:20 | |
| Clark Cox | Apr 20, 17:40 |






Cocoa mail archive

