Skip to content

Instantly share code, notes, and snippets.

@mikeabdullah
Created March 12, 2011 14:37
Show Gist options
  • Save mikeabdullah/867278 to your computer and use it in GitHub Desktop.
Save mikeabdullah/867278 to your computer and use it in GitHub Desktop.
More informative debugging description for NSError
- (NSString *)debugDescription;
{
// Log the entirety of domain, code, userInfo for debugging.
// Operates recursively on underlying errors
NSMutableDictionary *dictionaryRep = [[self userInfo] mutableCopy];
[dictionaryRep setObject:[self domain]
forKey:@"domain"];
[dictionaryRep setObject:[NSNumber numberWithInteger:[self code]]
forKey:@"code"];
NSError *underlyingError = [[self userInfo] objectForKey:NSUnderlyingErrorKey];
NSString *underlyingErrorDescription = [underlyingError debugDescription];
if (underlyingErrorDescription)
{
[dictionaryRep setObject:underlyingErrorDescription
forKey:NSUnderlyingErrorKey];
}
// Finish up
NSString *result = [dictionaryRep description];
[dictionaryRep release];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment