idiomatic way to collect and report multiple exceptions?

Chris Rebert crebert at ucsd.edu
Fri May 7 21:24:24 EDT 2010


> On May 6, 2010, at 10:56 PM, Chris Rebert wrote:
>> On Thu, May 6, 2010 at 8:50 PM, Ben Cohen <ncohen at ucsd.edu> wrote:
>>> Is there a pythonic way to collect and display multiple exceptions at the same time?
>>>
>>> For example let's say you're trying to validate the elements of a list and you'd like to validate as many of the elements as possible in one run and still report exception's raised while validating a failed element.
>>>
>>> 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)
>>>
>>> where if the raised MultipleValidationErrors exception goes uncaught the interpreter will print a nice traceback that includes the tracebacks of each raised ValidationError.  But I don't know how MultipleValidationErrors should be written ...
<my implementation snipped>

On Fri, May 7, 2010 at 6:06 PM, Ben Cohen <ncohen at ucsd.edu> wrote:
> Many thanks for the excellent example!!  You rock!
>
> Ben

However, I do agree with Steven that this approach to error handling
is unusual. But I assume you have your reasons for wanting to do it
this way.

Cheers,
Chris
--
Python + Bioinformatics = Win
http://blog.rebertia.com



More information about the Python-list mailing list