如何在 Python 中捕獲 ArithmeticError 異常?
ArithmeticError 異常是所有數字計算中出現的錯誤的基本類。它是這些內建異常的基本類: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 <type 'exceptions.ZeroDivisionError'> This is an example of catching ArithmeticError
廣告