CP学习笔记(8) - try: except 语句

try:
    <try suite>                      # always excecute
except <exception class> as <name>:  # <exception class> can be subclass of Exception Class
    <except suite>                   # excecuted when excecuting <try suite> meets errors

栗子

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

posted on 2015-12-15 20:02  Rim99  阅读(183)  评论(0编辑  收藏  举报

导航