1 # -*- coding:utf-8 -*- 2 name = 'tj' 3 try: 4 int(name) 5 except (IndexError,KeyError) as e: # 當有IndexError或KeyError時執行 6 print(e) 7 print(1) 8 except ValueError as e: # 當有ValueError時執行 9 print(e) 10 print(2) 11 except Exception as e: # 抓取所有例外 12 print(e) 13 print(3) 14 else: # 無例外時執行 15 print("一切正常") 16 finally: # 無論如何都執行 17 print("anywhere")
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/67463.html
標籤:Python
上一篇:Python--反射
