last exception backtrace (0) when using NSLog()

Hi,


One of my crash reports says that it was caused by using the NSLog() when there is an error retrieving the contents of a URL. If there is no error obviously this line does not execute, therefore no crash. When i debug the line prints to the log fine. The crash report was obtained from the organizer in xcode, and said it happened on 13 devices. Any help would be appreciated.


// This is the line of code that the crash report points to

NSLog(@"Error: Error retrieving JSON Data from URL https://subdomain.domain.com/theNameOfTheFile.json");



NSString *theJSON = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];

if (error) {

NSLog(@"Error: Error retrieving JSON Data from URL https://subdomain.domain.com/theNameOfTheFile.json");

return;

}

Please post an example crash report.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Do not check error to determine if there has been an error. Check the return value from the function (theJSON). Only if that indicates failure (has a nil value) should you examine error. It's quite possible that the -stringWithContentsOfURL:... method succeeded and your code is mistakenly acting as though it had failed.


Is the URL really in the string literal like you've shown? I understand that you changed the URL. Does the real URL contain a percent ('%') character? The first argument to NSLog() is interpreted as a format string. If it has any percent characters, they will be interpreted as format specifiers. It's quite likely to try to access a subsequent parameter that's not really there, and crash.

last exception backtrace (0) when using NSLog()
 
 
Q