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

Exception Handling ใน Python คืออะไร

Error: ผิดพลาดตอน compile (syntax error)

'abe' = 5
SyntaxError: can't assign to literal

Exception: Error ตอน execution (runtime) syntactically correct แต่ run ไม่ได้

abe < 5
NameError: name 'abe' is not defined

Python script พบ error ที่ handle ไม่ได้ → raise exception → create exception object

ถ้าไม่ handle → program terminate + print traceback

Exception handling ใช้เมื่อ: คิดว่า code อาจ produce error