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

วิธี Catch ArithmeticError Exception ใน Python

ArithmeticError เป็น base class ของ OverflowError, ZeroDivisionError, FloatingPointError

ตัวอย่าง

import sys

try:
    7/0
except ArithmeticError as e:
    print(e)
    print(sys.exc_type)
    print('This is an example of catching ArithmeticError')

ผลลัพธ์

integer division or modulo by zero

This is an example of catching ArithmeticError