Re: What is the expected Cocoa API behavior in an incomplete object traversal?
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: Corbin Dunn <email@hidden>
- Date: Fri, 15 Oct 2010 12:55:18 -0700
Hey Tito,
It depends. Does your method require all objects in the array to conform to a protocol? If yes, and one doesn't, then throw an exception, since it is a programming error. If no, meaning you allow some to pass through with nothing happening, then you should define the behavior in a header comment and/or documentation. If it is instead some array input that the user provided, and it is a user error to provide the wrong input, then you should return a user-presentable NSError and the caller should present the error on failure.
--corbin
On Oct 15, 2010, at 12: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?
>
> 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