日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

try....exception....finally

發(fā)布時間:2024/4/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 try....exception....finally 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
class MyException(Exception):def __init__(self,msg):self.msg=msgdef __str__(self):return self.msgtry:print('start')raise MyException('this is a custom exception')##手動觸發(fā)會被Exception捕獲 except Exception as e:print(e) finally:print('end')

##ret start this is a custom exception end import time try:print('start...')time.sleep(10) except KeyboardInterrupt as e:##按ctrl+c會執(zhí)行這個語句塊print('you press ctrl+c') finally:print('end...')


myexception=MyException('231') print(hasattr(myexception,'msg'))#True print(hasattr(myexception,'msg1'))#False print(getattr(myexception,'__str__')())#231 setattr(myexception,'fun',lambda x:x) print(getattr(myexception,'fun')(1234))#1234 delattr(myexception,'fun')

?

try: l = ["a", "b"] int(l[2]) except (ValueError, IndexError) as e: pass

?

  

轉(zhuǎn)載于:https://www.cnblogs.com/howhy/p/7828340.html

總結(jié)

以上是生活随笔為你收集整理的try....exception....finally的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。