How can I get more useful information from NSError? How can I get more useful information from NSError? ios ios

How can I get more useful information from NSError?


Finally, I follow code for perfect NSError print.Thanks @jbat100 and @Peter Warbo, I add a little bit on them code:

    NSDictionary *userInfo = [error userInfo];    NSString *errorString = [[userInfo objectForKey:NSUnderlyingErrorKey] localizedDescription];


How about:

NSDictionary *userInfo = [error userInfo];NSString *error = [userInfo objectForKey:@"NSUnderlyingError"];NSLog(@"The error is: %@", error);


If you look up the NSError documentation, it has a User info dictionary keys section which has a constant defined as NSUnderlyingErrorKey (it also has a description for the keys).

NSDictionary *userInfo = [error userInfo];NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];NSString *underlyingErrorDescription = [underlyingError localizedDescription];