try:
<測試敘述>
except:
<如果測試敘述發生異常則執行此區塊>
else:
<如果測試敘述未發生異常則執行此區塊>
finally:
<不論測試敘述是否發生異常皆執行此ㄑㄩ>
++++++++++++++++++++++++++++++++++
try:
raise ValueError
except:
print 'EXCP_BLOCK'
else:
print 'ELSE_BLOCK'
finally:
print 'FINAL_BLOCK'
=================== RESTART ==========================
>>>
EXCP_BLOCK
FINAL_BLOCK
try:
print 'TRY_BLOCK'
except:
print 'EXCP_BLOCK'
else:
print 'ELSE_BLOCK'
finally:
print 'FINAL_BLOCK'
======= RESTART ================================
>>>
TRY_BLOCK
ELSE_BLOCK
FINAL_BLOCK
沒有留言:
張貼留言