fuzzygoat
fuzzygoat

Reputation: 26223

Accessing Returned Information From NSError?

Does anyone know if I can extract just the verbose part of the returned error (i.e. "The file “maya.MEL” couldn’t be opened because the text encoding of its contents can’t be determined.")

NSError *fileError;
NSStringEncoding fileEncoding;
NSString *fileContents;

fileContents = [NSString stringWithContentsOfFile:fileOnDisk
                                     usedEncoding:&fileEncoding 
                                            error:&fileError];

When I use the following I get the output

NSLog(@"Error : %@", fileError);

Error : Error Domain=NSCocoaErrorDomain Code=264 UserInfo=0x100111a40 "The file “maya.MEL” couldn’t be opened because the text encoding of its contents can’t be determined."

NSLog(@"Error : %d", [fileError code]);
// Gives: 264

NSLog(@"Error : %@", [fileError domain]);
// Gives: NSCocoaErrorDomain

NSLog(@"Error : %@", [fileError userInfo]);
// Gives: NSFilePath = "/Users/Gary/Documents/Xcode/RnD/Maya.MEL";

gary

Upvotes: 1

Views: 1676

Answers (1)

fuzzygoat
fuzzygoat

Reputation: 26223

I think I have found it:

NSLog(@"Error : %@", [fileError localizedDescription]);

Upvotes: 4

Related Questions