How to catch ArithmeticError Exception in Python?

PythonServer Side ProgrammingProgramming

ArithmeticError Exception is the base class for all errors that occur for numeric calculations. It is the base class for those built-in exceptions like: OverflowError, ZeroDivisionError, FloatingPointError

We can catch the exception in given code as follows

Example

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

Output

integer division or modulo by zero
<type 'exceptions.ZeroDivisionError'>
This is an example of catching ArithmeticError
raja
Published on 06-Dec-2017 13:13:02
Advertisements