Capturing a NSParseErrorException

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-03-22T13:39:03Z Indexed on 2010/03/22 13:41 UTC
Read the original article Hit count: 307

Filed under:
|

Could someone tell me how I can capture a NSParseErrorException?

The Situation: my app downloads a small .plist file. I convert this into dictionary using the string method -propertylist. This normally works fine. I check for a connection before going to retrieve the file, so it works fine if I've got a connection to the internet, and works fine when I don't.

However, I discovered a use case that crashes. If I'm at location that requires authetication before connecting to the internet (at Starbucks, say) what's being returned by the app isn't a plist and the attempt to parse it causes the application to crash.

So is there a way to transform my code so that the NSParseErrorException is caught and rather than crashing the program I can just skip over this piece of code?

NSDictionary *temp = [myDownloadString propertyList];

I tried doing this

if ([myDownloadString propertyList]==NSParseErrorException){
//do something
}

but that didn't work.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c