idiomatic way to collect and report multiple exceptions?
Terry Reedy
tjreedy at udel.edu
Fri May 7 01:06:07 EDT 2010
On 5/6/2010 11:50 PM, Ben Cohen 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)
I believe each exception replaces the traceback message. So I would
collect tracebacks rather than exceptions. Try the traceback module.
Terry Jan Reedy
More information about the Python-list
mailing list