Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธี Ignore Exception และดำเนินต่อไปใน Python

ใช้ pass ใน except block

1. Bare except (จับ BaseException รวม KeyboardInterrupt, SystemExit)

try:
    1/0
except:
    pass

2. except Exception (ไม่จับ KeyboardInterrupt, SystemExit) - แนะนำ

try:
    1/0
except Exception:
    pass

pass ทำให้ข้าม exception ไปได้