Re: [newb] Allowing error-prone code line to persist in app
Re: [newb] Allowing error-prone code line to persist in app
- Subject: Re: [newb] Allowing error-prone code line to persist in app
- From: Kyle Sluder <email@hidden>
- Date: Tue, 18 Aug 2009 09:19:42 -0700
On Aug 18, 2009, at 9:11 AM, Chris Paveglio <email@hidden>
wrote:
NSString *formattedFax = [NSString stringWithFormat:@"%@-%@-%@",
[originalFax substringWithRange:NSMakeRange(0,3)], etc...
*** -[NSCFString substringWithRange:]: Range or index out of bounds
This is an error. You must fix it.
But if there is not a second phone/fax number, I don't really care
if this line fails. I certainly *could* write a check like "if
(originalFax != @"") then... continue with function". But would that
take more time to process?
You're concerned about a single if statement? You obviously haven't
yet understood the scale at which you're working; sending a message
alone performs multiple 'if' statements.
So SHOULD I write the check to make sure the data is valid or not?
Or just let the function fail because its faster and has no lasting
impact? Is it OK if this line quietly (to the user) fails?
Not checking input for validity is a recipe for disaster.
The code as written raises an exception. This is hardly "zero impact."
And it's not silent, either. The notice will appear in Console.app.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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