- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 FloatingPointError Exception in Python?
FloatingPointError is raised by floating point operations that result in errors, when floating point exception control (fpectl) is turned on. Enabling fpectl requires an interpreter compiled with the --with-fpectl flag.
The given code is rewritten as follows to handle the exception and find its type.
Example
import sys import math import fpectl try: print 'Control off:', math.exp(700) fpectl.turnon_sigfpe() print 'Control on:', math.exp(1000) except Exception as e: print e print sys.exc_type
Output
Control off: 1.01423205474e+304 Control on: in math_1 <type 'exceptions.FloatingPointError'>
Advertisements