• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSError help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSError help


  • Subject: Re: NSError help
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Sun, 24 Oct 2010 18:06:49 -0500

On Sun, Oct 24, 2010 at 5:54 PM, Tom Jones <email@hidden> wrote:
> -(NSString *)getDataForType:(NSString *)aType error:(NSError **)err
> {
>    NSError *localErr = nil;
>    NSString *result = [self getDataForType:aType separator:@"\t" excludeFields:nil error:&localErr];
>    *err = *localErr;
>    return result;
> }
>
> -(NSString *)getDataForType:(NSString *)aType excludeFields:(NSArray *)aFields error:(NSError **)err
> {
>    NSError *localErr = nil;
>    NSString *result = [self getDataForType:aType separator:@"\t" excludeFields:aFields error:&localErr];
>    *err = *localErr;
>    return result;
> }

(1) In Cocoa convention, methods that being with "get" return accept a
pointer to a type and return their data through it. See -[NSString
getCharacters:range:] for example. Your method should probably be
called simply "dataForType:error:". (2) Convention again says that the
error parameter is optional, and if you don't need it to pass
NULL/nil. In that case, your line "*err = *localErr;" will segfault
because you are derferencing NULL. You need to check for NULL before
trying to dereference it. (3) The localErr stuff is pointless anyway.
You could just as well do: "[self getDataForType:aType separator:@"\t"
excludeFields:aFields error:err]".

> -(NSString *)getDataForType:(NSString *)aType separator:(NSString *)aSeperator excludeFields:(NSArray *)aFields error:(NSError **)err
> {
>    BOOL isValidQuery = [self hasValidType:aType];
>    if (isValidQuery == NO) {
>        NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary];
>        [errorDetail setValue:@"Failed to find the requested type." forKey:NSLocalizedDescriptionKey];
>        *err = [NSError errorWithDomain:@"DataForType" code:1 userInfo:errorDetail];

Again, you need to check that err is NULL before trying to dereference it.

>        return nil;
>    } else {
>        err = nil;

This line will never do anything.

>    }
> ...
> ...
> ...
> }
_______________________________________________

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

References: 
 >NSError help (From: Tom Jones <email@hidden>)

  • Prev by Date: Re: NSError help
  • Next by Date: Re: NSError help
  • Previous by thread: Re: NSError help
  • Next by thread: Re: NSError help
  • Index(es):
    • Date
    • Thread