如何在 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
广告