EnvironmentError Exception in Python Last Updated : 21 Aug, 2020 Comments Improve Suggest changes 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 EnvironmentError Exception 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 How to pass argument to an Exception in Python? There might arise a situation where there is a need for additional information from an exception raised by Python. Python has two types of exceptions namely, Built-In Exceptions and User-Defined Exceptions.Why use Argument in Exceptions? Using arguments for Exceptions in Python is useful for the fol 2 min read Python Exception Handling Python Exception Handling handles errors that occur during the execution of a program. Exception handling allows to respond to the error, instead of crashing the running program. It enables you to catch and manage errors, making your code more robust and user-friendly. Let's look at an example:Handl 7 min read NZEC error in Python While coding on various competitive sites, many people must have encountered NZEC errors. NZEC (non-zero exit code), as the name suggests, occurs when your code fails to return 0. When a code returns 0, it means it is successfully executed otherwise, it will return some other number depending on the 2 min read User-defined Exceptions in Python with Examples In Python, exceptions are used to handle errors that occur during the execution of a program. While Python provides many built-in exceptions, sometimes we may need to create our own exceptions to handle specific situations that are unique to application. These are called user-defined exceptions.To m 4 min read Like