Cathing several potential errors?

Gary Josack gary at byoteki.com
Sun Sep 7 00:38:59 CEST 2008


cnb wrote:
> if i do
> try:
>     something
> except TypeError, IndexError:
>     pass
>
> only the first error will get caught. I dont want to use Exception and
> catch all errors, but just 2. how can i do that?
> --
> http://mail.python.org/mailman/listinfo/python-list
>   
what you're doing is assigning the value of TypeError to the name IndexError

try:
  somthing
except (TypeError, IndexError):
  pass

use

except (TypeError, IndexError), e:
  print e

if you want to print the error



More information about the Python-list mailing list