idiomatic way to collect and report multiple exceptions?

Ben Cohen ncohen at ucsd.edu
Sat May 8 01:22:08 EDT 2010


Apologies for the TABs -- I wrote that example for demonstration purposes in my mail client -- I'll copy and paste from a real code editor in the future.
Ben

On May 7, 2010, at 3:28 PM, Aahz wrote:

> In article <mailman.2715.1273204222.23598.python-list at python.org>,
> Ben Cohen  <ncohen at ucsd.edu> wrote:
>> 
>> eg -- I'd like to do something like this:
>> 
>> errors = []
>> for item in data:
>>   try:
>>       process(item)
>>   except ValidationError as e:
>>       errors.append(e)
>> raise MultipleValidationErrors(*errors)
> 
> First of all, please DO NOT post code with TABs in it.  In fact, you
> shouldn't even be writing code with TABs -- TAB characters are obsolete
> for new Python code.
> 
> I would write your code this way:
> 
> errors = []
> for item in data:
>    try:
>        process(item)
>    except ValidationError as e:
>        errors.append(str(e))
> if errors:
>    raise MultipleValidationErrors(errors)
> -- 
> Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/
> 
> f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
> -- 
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list