I have a list of objects that need to be processed in some way. That way may not be correct for an item and thus raise an exception. In pseudo-code, it would look like:
proccessItems (list)
error = new empty list
for item in list:
try:
process_item(item)
catch Whatever, err:
error.append(err)
return error
Is there a pattern for doing this sort of things? Are there any anti-patterns to avoid?
A better code (exception not used for control flow), but still following the same logic would be:
proccessItems (list)
error = new empty list
for item in list:
ret = process_item(item)
if null != ret
error.append(ret)
return error
process_item(). – Clockwork-Muse Nov 25 '11 at 22:36