Skip navigation.
 
mlRe: Should a Method set NSError* to nil when No Error?
FROM : Jean-Daniel Dupas
DATE : Sun Apr 20 11:45:15 2008

Le 20 avr. 08 à 01:03, Uli Kusterer a écrit :

> Am 19.04.2008 um 18:46 schrieb Jerry Krinock:

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

>
>
> Well, when Apple code doesn't specify it will be set to NIL, one 
> can't rely on that, so definitely rely on the return value for those.
>
> However, when I write my own code, I like to set the error variable 
> on NIL to indicate no error, because that's just better style. Then 
> again, I also initialize list counters in code like:
>
>     int x = 0;
>     for( x = 0; x < maxCount(); x++ )
>         ;
>
> Simply because you'll never know who is going to insert their own 
> code between those two lines and re-use x. Even if you work alone, 
> you may screw up two years from now.


I greatly prefere the C99 way to do it. It prevents variables conflict 
if you have more than one loop in your method.

for (int idx = 0; idx < maxCount(); idx++) {

}

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