Language Syntax

Except — Python syntax

Handle the first matching exception clause, including subclasses. A tuple can match several exception types. The as target is cleared at the end of the handler to reduce reference cycles.

Formal Syntax & Structure

python syntaxpython
except ExceptionType as name:    suite

Working Example

Example Snippetpython
try:    int('x')except (ValueError,TypeError) as error:    result=type(error).__name__print((result,'error' in globals()))
Python Reference