- 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 ZeroDivisionError Exception in Python?
When zero shows up in the denominator of a division operation, a ZeroDivisionError is raised.
We re-write the given code as follows to handle the exception and find its type.
Example
import sys try: x = 11/0 print x except Exception as e: print sys.exc_type print e
Output
<type 'exceptions.ZeroDivisionError'> integer division or modulo by zero
Advertisements