Python - Catching any and all exceptions

Introduction

except clauses list no exception name (except:) catch all exceptions not previously listed in the try statement.

except clauses can list a set of exceptions in parentheses (except (e1, e2, e3):) catch any of the listed exceptions.

try: 
    action() 
except NameError: 
    ... 
except IndexError: 
    ... 
except KeyError: 
    ... 
except (AttributeError, TypeError, SyntaxError): 
    ... 
else: 
    ... 

Related Topic