python 的err輸出BaseException

try:
print('try...')
r = 10 / 0
print('result:', r)
except BaseException as e:
print('except:',e)
finally: ##能夠添加,或者刪除,都會執行。html

print('finally...')

print('END')python

此外,若是沒有錯誤發生,能夠在except語句塊後面加一個else,當沒有錯誤發生時,會自動執行else語句:ide

try:
    print('try...')
    r = 10 / int('2')
    print('result:', r)
except ValueError as e:
    print('ValueError:', e)
except ZeroDivisionError as e:
    print('ZeroDivisionError:', e)
else:
    print('no error!')
finally:
    print('finally...')
print('END')

http://www.runoob.com/python/python-exceptions.htmlcode

相關文章
相關標籤/搜索