美文网首页
try: except 语句

try: except 语句

作者: Rim99 | 来源:发表于2015-12-15 20:05 被阅读23次
try:
    <try suite>                      # always executed
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

相关文章

网友评论

      本文标题:try: except 语句

      本文链接:https://www.haomeiwen.com/subject/xpiuhttx.html