- 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 IOError Exception in Python?
IOError Exception
It is an error raised when an input/output operation fails, such as the print statement or the open() function when trying to open a file that does not exist. It is also raised for operating system-related errors.
If the given code is written in a try block, it raises an input/output exception, which is handled in the except block as shown given below
Example
import sys def whatever(): try: f = open ( "foo.txt", 'r' ) except IOError, e: print e print sys.exc_type whatever()
Output
[Errno 2] No such file or directory: 'foo.txt' <type 'exceptions.IOError'>
Advertisements