• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Design Option: Exception handling vs Code Testing....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Design Option: Exception handling vs Code Testing....


  • Subject: Re: Design Option: Exception handling vs Code Testing....
  • From: Michael Ash <email@hidden>
  • Date: Thu, 10 Jun 2010 16:04:46 -0700

On Thursday, June 10, 2010, Kyle Sluder <email@hidden> wrote:
> On Thu, Jun 10, 2010 at 1:58 PM, Frederick C.Lee
> <email@hidden> wrote:
>> Greetings:
>>    I have a situation where I need to access a member of a mutable array (max 4 members).
>> Sometimes I could get an out-of-bounds exception, if for example, I try to access member #3 out of a 2-member array.
>> It's not serious, I could just ignore it and continue.
>
> No, you cannot. It is illegal and must not be done.
>
> Just check the count of the array before accessing it. But the fact
> that you have this possibility at all is indicative of poor design.

It's not illegal; objectAtIndex: is documented to throw a range
exception if you access something off the end. Relying on that is just
using documented behavior. It's not a good idea and is deeply contrary
to standard Cocoa idioms, but it's in no way illegal.

Mike
_______________________________________________

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

References: 
 >Design Option: Exception handling vs Code Testing.... (From: Frederick C.Lee <email@hidden>)
 >Re: Design Option: Exception handling vs Code Testing.... (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Design Option: Exception handling vs Code Testing....
  • Next by Date: Re: FSCopyObjectAsync hogging the thread?
  • Previous by thread: Re: Design Option: Exception handling vs Code Testing....
  • Next by thread: Re: Design Option: Exception handling vs Code Testing....
  • Index(es):
    • Date
    • Thread