Python - Catching all: The empty except and Exception

Introduction

To have a general "catchall" clause, an empty except does the trick:

try: 
    action() 
except NameError: 
    ...                   # Handle NameError 
except IndexError: 
    ...                   # Handle IndexError 
except: 
    ...                   # Handle all other exceptions 

else: 
    ...                   # Handle the no-exception case 

The empty except clause is a sort of wildcard feature.

It catches everything.

The following catches everything without listing anything:

try: 
    action() 
except: 
    ...                   # Catch all possible exceptions 

Related Topic