• 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: Tom Jones <email@hidden>
  • Date: Mon, 25 Oct 2010 08:22:31 -0700 (PDT)

Thanks,
Yes, the compiler was complaining about the "*err = *localErr;". I origionally had it to be "*err = localErr;" but I was still getting a EXC_BAD_ACCESS error. But then the light bulb went off :-)when I read "he isn't checking for nil err", and that is exactly what was my problem.

I changed the code a bit per your suggestions.

return [self getDataForType:aType separator:@"\t" excludeFields:nil error:err];

But the other change I had to make was

if(err) {
    NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary];
    [errorDetail setValue:@"Failed to find the requested type." forKey:NSLocalizedDescriptionKey];
    *err = [NSError errorWithDomain:@"DataForType" code:1 userInfo:errorDetail];
}

return nil;

Thanks for the help,
tom

----- Original Message -----
From: "Ken Thomases" <email@hidden>
To: "Tom Jones" <email@hidden>
Cc: email@hidden
Sent: Sunday, October 24, 2010 4:05:19 PM
Subject: Re: NSError help

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

> 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?

> -(NSString *)getDataForType:(NSString *)aType error:(NSError **)err
> {
>    NSError *localErr = nil;
>    NSString *result = [self getDataForType:aType separator:@"\t" excludeFields:nil error:&localErr];
>    *err = *localErr;

This is incorrect.  The left and right sides are of two different types.  The compiler should have at least warned, if not given an error.

"*localErr" is an NSError.  It's not an NSError* (pointer to NSError), it's actually the type of the object (or struct).  There's almost never a case to dereference an object pointer like this.

"*err" is an NSError*, a pointer to an NSError.

What you wanted is:

	*err = localErr;

Actually, if you're not doing more with localErr, you can just eliminate it and just do:

   NSString *result = [self getDataForType:aType separator:@"\t" excludeFields:nil error:err];

The same mistake affects the next method, too.

>    return result;
> }

Regards,
Ken

_______________________________________________

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: 
 >Re: NSError help (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Debugging a self made Framework
  • Next by Date: Drag and drop between 2 table views
  • Previous by thread: Re: NSError help
  • Next by thread: Re: NSError help
  • Index(es):
    • Date
    • Thread