Re: Crashing on writing to NSLog?
Re: Crashing on writing to NSLog?
- Subject: Re: Crashing on writing to NSLog?
- From: "stephen joseph butler" <email@hidden>
- Date: Thu, 22 Feb 2007 16:05:14 -0600
2007/2/22, Paul Borokhov <email@hidden>:
Is it possible that I am crashing my application by writing data to the Console using NSLog? Namely, I have a try/catch block and in the catch block I write the error's description, like so:
@try {
...stuff...
} @catch (NSException *exception) {
if ([[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"logErrors"]) {
NSLog( @"Notifications Fetch Error");
NSLog([[exception name] stringByAppendingString:[exception reason]]);
}
If "logErrors" is set to TRUE, then I can generate at least one specific error that will crash the app. If it's set to FALSE, the app doesn't crash.
Is this possible, or just a red herring?
You shouldn't ever pass an arbitrary string like this to a formatting
function. What if it contains a % escape sequence? Try this:
NSLog(@"%@", [[exception name] stringByAppendingString:[exception reason]]);
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden