Python知識分享網(wǎng) - 專業(yè)的Python學習網(wǎng)站 學Python,上Python222
Python 異常的傳遞性
發(fā)布于:2023-09-13 10:01:51

Python 7天快速入門完整視頻教程https://www.bilibili.com/video/BV1o84y1Z7J1

 

Python   異常的傳遞性

 

異常是具有傳遞性的,假如方法A調(diào)用方法B,方法B調(diào)用方法C,如果方法C代碼出現(xiàn)異常,并且沒有處理異常,則會傳遞給方法B,同理,如果B依然沒有處理異常,則最終傳遞給方法A。

 

def funC():
    print("funC開始")
    a = 1 / 0
    print("funC結束")


def funB():
    print("funB開始")
    funC()
    print("funB結束")


def funA():
    print("funA開始")
    funB()
    print("funA結束")


try:
    funA()
except Exception as e:
    print(e)

 

 

 

轉(zhuǎn)載自: