Cathing several potential errors?

John Machin sjmachin at
Sat Sep 6 18:42:37 EDT 2008

On Sep 7, 8:13 am, cnb <circularf... at> 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?

The syntax for what you can have between "except" and ":" is:
    [expression  ["," target]]
'target' is an optional name to be bound to the actual exception
object that is raised.
If you want to catch multiple kinds of exception, 'expression' needs
to be a tuple.



More information about the Python-list mailing list