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: 2020-06-12T08:07:42+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements