What's the best way to log an NSError?
- (void)epicFail:(Lol *)aLol withError:(NSError *)error
{
NSLog(@"Error: %@", error);
}
Gives me a null message
Thanks.
What's the best way to log an NSError?
- (void)epicFail:(Lol *)aLol withError:(NSError *)error
{
NSLog(@"Error: %@", error);
}
Gives me a null message
Thanks.
NSLog(@"Error: %@", error);
Gives me a null message
Then error
is nil
, not an NSError instance.
Looking at the NSError documentation tells me that you'll need to do something like:
NSLog(@"%@",[error localizedDescription]);
This should then give you human readable output
Here's a rough method I use to log errors while developing; (Not for Cocoa-touch)
// Execute the fetch request put the results into array
NSError *error = nil;
NSArray *resultArray = [moc executeFetchRequest:request error:&error];
if (resultArray == nil)
{
// Diagnostic error handling
NSAlert *anAlert = [NSAlert alertWithError:error];
[anAlert runModal];
}
NSAlert takes care of displaying the error.