• 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: What is the expected Cocoa API behavior in an incomplete object traversal?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the expected Cocoa API behavior in an incomplete object traversal?


  • Subject: Re: What is the expected Cocoa API behavior in an incomplete object traversal?
  • From: "Hank Heijink (Mailinglists)" <email@hidden>
  • Date: Fri, 15 Oct 2010 16:03:38 -0400

On Oct 15, 2010, at 3:42 PM, Tito Ciuro wrote:

> Hello,
>
> I'm implementing a method and I'm not sure what the behavior should be when detecting an anomaly.
>
> Case in point: I have a method that iterates through an array of objects. As I traverse the array, I'm, checking whether the object in the array conforms to a custom protocol. If it does, everything is fine and I process it. However, if at some point I detect that the array contains a non-conforming object, what should the method do?:
>
> a) skip the non-conforming object and continue processing and return a BOOL or fill an NSError?
> b) stop processing and return a BOOL or fill an NSError?
> c) throw an exception?

http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Exceptions/Exceptions.html#//apple_ref/doc/uid/10000012i
http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html#//apple_ref/doc/uid/TP40001806

It depends on your situation: if you expect this situation to occur in normal usage, you shouldn't throw an exception. If the situation you describe means you've got a bug in your program, an exception or an assert is the right answer.

Cheers,
Hank

PS. These links happen to be in the iOS library (Google ranks iOS higher than Mac OS these days), but afaik the Mac OS docs are identical.

> Since the method would end up processing less objects that the developer intended, I wonder what Cocoa developers would expect in this case...
>
> Thanks,
>
> -- Tito
> _______________________________________________
>
> 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
>

_______________________________________________

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: 
 >What is the expected Cocoa API behavior in an incomplete object traversal? (From: Tito Ciuro <email@hidden>)

  • Prev by Date: Re: What is the expected Cocoa API behavior in an incomplete object traversal?
  • Next by Date: Re: What is the expected Cocoa API behavior in an incomplete object traversal?
  • Previous by thread: Re: What is the expected Cocoa API behavior in an incomplete object traversal?
  • Next by thread: Re: What is the expected Cocoa API behavior in an incomplete object traversal?
  • Index(es):
    • Date
    • Thread