How can I view NSError?

What is the best way to register an NSError ?

 - (void)checkThing:(Thing *)thing withError:(NSError *)error { NSLog(@"Error: %@", error); } 

Gives me a null message

+49
logging objective-c iphone cocoa
Oct. 13 '09 at 9:38
source share
3 answers

The NSError documentation tells you that you need to do something like:

 NSLog(@"%@",[error localizedDescription]); 

This will then give you user-friendly output.

+102
Oct 13 '09 at 11:29
source share
 NSLog(@"Error: %@", error); 

Gives me a null message

Then error is nil , not an instance of NSError.

+19
Oct 13 '09 at 10:20
source share

Here is a rough method that I use to log errors during development; (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.

+1
Oct 13 '09 at 17:01
source share



All Articles