• 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: Dave Carrigan <email@hidden>
  • Date: Sun, 24 Oct 2010 16:11:20 -0700

On Oct 24, 2010, at 3:54 PM, Tom Jones wrote:

> Hello,
> I'm trying to understand why I'm getting thrown in to the debugger when using NSError. I have three methods and I'm overloading them and trying to pass the NSError along the way. What am I doing wrong?
>
> Thanks,
> tom
>
>
> Code:
>
> -(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;
> }

This is assigning an objective-C class object (however big it happens to be) to a pointer. It makes no sense. I'm not even sure how it could have compiled without errors or warnings.

>
> -(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;
> }

Same as above.

>
> -(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];
>        return nil;
>    } else {
> 	err = nil;
>    }
> ...
> ...
> ...
> }

This is fine, although the code in the else is useless. If you mean to make the pointer pointed to by err to nil, then maybe *err=nil would be OK, although typical Cocoa idiom is that err is meaningless if the function succeeds, so there's not really any need to set it to anything at all, except on failure.

_______________________________________________

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: NSMutableURLRequest google my maps help
  • Previous by thread: Re: NSError help
  • Next by thread: Re: NSError help
  • Index(es):
    • Date
    • Thread