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

วิธีอธิบายว่า Exception เป็น Object ใน Python

ใน Python ทุกอย่างคือ Object รวมถึง Exceptions

Exception object มี attributes และ methods เช่นเดียวกับ list, function, tuple

  • Base class: Exception
  • Attributes: e.args, e.message

Current implementation: exceptions ประกอบด้วย 3 ส่วน (type, value, traceback) เข้าถึงได้ผ่าน sys.exc_info()

ตัวอย่าง output

(, ValueError('could not convert string to int: Godzilla!',), )