EnvironmentError Exception in Python Last Updated : 21 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. 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".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 : Python3 # importing the module import sys try: # an invalid path file = open("GeeksforGeeks.txt", 'r') except Exception as e: print(e) print(sys.exc_info()[0]) Output[Errno 2] No such file or directory: 'GeeksforGeeks.txt' <class 'FileNotFoundError'> Example 2 : Python3 # importing the module import os import sys try: for i in range(7): print(i) print(os.ttyname(i)) except Exception as e: print(e) print(sys.exc_info()[0]) Output0 [Errno 25] Inappropriate ioctl for device <class 'OSError'> Example 3 : Python3 # importing the module import sys import os try: # an invalid path os.rmdir('GEEKS') except Exception as e: print(e) print(sys.exc_info()[0]) Output[Errno 2] No such file or directory: 'GEEKS' <class 'FileNotFoundError'> Comment More infoAdvertise with us Next Article Errors and Exceptions in Python R rohanchopra96 Follow Improve Article Tags : Python Python-exceptions Practice Tags : python Similar Reads Errors and Exceptions in Python Errors are problems in a program that causes the program to stop its execution. On the other hand, exceptions are raised when some internal events change the program's normal flow. Syntax Errors in PythonSyntax error occurs when the code doesn't follow Python's rules, like using incorrect grammar in 3 min read Concrete Exceptions in Python In Python, exceptions are a way of handling errors that occur during the execution of the program. When an error occurs Python raises an exception that can be caught and handled by the programmer to prevent the program from crashing. In this article, we will see about concrete exceptions in Python i 3 min read Handling EOFError Exception in Python In Python, an EOFError is raised when one of the built-in functions, such as input() or raw_input() reaches the end-of-file (EOF) condition without reading any data. This commonly occurs in online IDEs or when reading from a file where there is no more data left to read. Example:Pythonn = int(input( 4 min read Python Built-in Exceptions In Python, exceptions are events that can alter the flow of control in a program. These errors can arise during program execution and need to be handled appropriately. Python provides a set of built-in exceptions, each meant to signal a particular type of error.We can catch exceptions using try and 8 min read Create an Exception Logging Decorator in Python Prerequisites: Decorators in Python, Logging in Python Logging helps you to keep track of the program/application you run. It stores the outputs/errors/messages/exceptions anything you want to store. Program executions can be debugged with the help of print statements during the runtime of code. But 2 min read Python Print Exception In Python, exceptions are errors that occur at runtime and can crash your program if not handled. While catching exceptions is important, printing them helps us understand what went wrong and where. In this article, we'll focus on different ways to print exceptions.Using as keywordas keyword lets us 3 min read Like