try: except 语句

try:
                          # always executed
except  as :  #  can be subclass of Exception Class
                       # excecuted when excecuting  meets errors

栗子

>>> try:
        x = 1/0
    except ZeroDivisionError as e:
        print('handling a', type(e))
        x = 0
handling a 
>>> x
0

你可能感兴趣的:(try: except 语句)