VOOZH about

URL: https://www.geeksforgeeks.org/python/environmenterror-exception-in-python/

⇱ EnvironmentError Exception in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

EnvironmentError Exception in Python

Last Updated : 21 Aug, 2020

EnvironmentError is the base class for errors that come from outside of Python (the operating system, file system, etc.). It is the parent class for IOError and OSError exceptions. 

  1. exception IOError - It is raised when an I/O operation (when a method of a file object ) fails. e.g "File not found" or "Disk Full".
  2. exception OSError - It is raised when a function returns a system-related error.

Any example of an IOError or OSError should also be an example of Environment Error.

Example 1 :


Output
[Errno 2] No such file or directory: 'GeeksforGeeks.txt'
<class 'FileNotFoundError'>

Example 2 :


Output
0
[Errno 25] Inappropriate ioctl for device
<class 'OSError'>

Example 3 :


Output
[Errno 2] No such file or directory: 'GEEKS'
<class 'FileNotFoundError'>
Comment
Article Tags: