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 protected]>
To: "Tom Jones" <[email protected]>
Cc: [email protected]
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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]