如何在Python中捕捉ArithmeticError异常?
ArithmeticError异常是在数字计算中发生的所有错误的基类。它是 OverflowError、ZeroDivisionError、FloatingPointError 等内置异常的基类。
我们可以像以下代码一样捕捉异常。
示例
import sys
try:
7/0
except ArithmeticError as e:
print e
print sys.exc_type
print '这是捕捉ArithmeticError的示例'
输出
integer division or modulo by zero
<type 'exceptions.ZeroDivisionError'>
这是捕捉ArithmeticError的示例
极客教程