Skip navigation.
 
mlShould a Method set NSError* to nil when No Error?
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?

Related mailsAuthorDate
mlShould a Method set NSError* to nil when No Error? Jerry Krinock Apr 19, 18:46
mlRe: Should a Method set NSError* to nil when No Error? Bill Bumgarner Apr 19, 20:24
mlRe: Should a Method set NSError* to nil when No Error? Jerry Krinock Apr 19, 22:10
mlRe: Should a Method set NSError* to nil when No Error? Ali Ozer Apr 20, 00:11
mlRe: Should a Method set NSError* to nil when No Error? Uli Kusterer Apr 20, 01:03
mlRe: Should a Method set NSError* to nil when No Error? Jean-Daniel Dupas Apr 20, 11:45
mlRe: Should a Method set NSError* to nil when No Error? Uli Kusterer Apr 20, 16:20
mlRe: Should a Method set NSError* to nil when No Error? Clark Cox Apr 20, 17:40