- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to catch OverflowError Exception in Python?
When an arithmetic operation exceeds the limits of the variable type, an OverflowError is raised. Long integers allocate more space as values grow, so they end up raising MemoryError. Floating point exception handling is not standardized, however. Regular integers are converted to long values as needed.
Example
Given code is rewritten to catch exception as follows
i=1 try: f = 3.0**i for i in range(100): print i, f f = f ** 2 except OverflowError as err: print 'Overflowed after ', f, err
Output
We get following OverflowError as output as follows
C:/Users/TutorialsPoint1/~scratch_1.py Floating point values: 0 3.0 1 9.0 2 81.0 3 6561.0 4 43046721.0 5 1.85302018885e+15 6 3.43368382029e+30 7 1.17901845777e+61 8 1.39008452377e+122 9 1.93233498323e+244 Overflowed after 1.93233498323e+244 (34, 'Result too large')
- Related Articles
- How to catch KeyError Exception in Python?
- How to catch IOError Exception in Python?
- How to catch ArithmeticError Exception in Python?
- How to catch IndexError Exception in Python?
- How to catch NameError Exception in Python?
- How to catch EOFError Exception in Python?
- How to catch SyntaxError Exception in Python?
- How to catch IndentationError Exception in python?
- How to catch TypeError Exception in Python?
- How to catch EnvironmentError Exception in Python?
- How to catch LookupError Exception in Python?
- How to catch ZeroDivisionError Exception in Python?
- How to catch FloatingPointError Exception in Python?
- How to catch StandardError Exception in Python?
- How to catch StopIteration Exception in Python?

Advertisements