How to catch ArithmeticError Exception in Python?


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

Updated on: 12-Jun-2020

791 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements