
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33578 Articles for Programming

840 Views
The OSError in Python is commonly encountered when a system-related error occurs, such as a file not found, permission denied, or disk I/O errors. It is one of the built-in exceptions that helps in handling operating system-level failures. In this article, you will learn how to catch and handle OSError using try-except blocks with examples. When Does OSError Occur? OSError may occur in the following situations - Trying to open a non-existent file. Permission denied while accessing a file or directory. Invalid file path or I/O operation failures. Example: File Not Found In the following example, we try ... Read More

1K+ Views
The NotImplementedError exception in Python is raised when an abstract method or operation that should be implemented by a subclass is not implemented. It is commonly used as a placeholder in base classes to indicate that subclasses are expected to override the method. In this article, you will learn how to catch and handle the NotImplementedError in Python using simple examples. When Does NotImplementedError Occur? The NotImplementedError is usually raised in the following cases - A method is defined in a base class but is not implemented and used as a placeholder for child classes to override. The subclass ... Read More

4K+ Views
The ImportError exception in Python is raised when the interpreter cannot find or load a module that is being imported using the import statement. Catching the ImportError ExceptionLike any other exception, we can catch the ImportError exception using the try-except blocks. In this article, we discuss various scenarios where the ImportError exception occurs, with examples, and catch the generated exception using the try-except blocks in each scenario.When Does ImportError Occur?The ImportError generally occurs in the following cases -Trying to import a module that doesn't exist.Misspelling the module name.Trying to import a function or class that is not available in the specified module.Example: Importing a ... Read More

2K+ Views
The SystemExit exception in Python is raised when the sys.exit() function is called. It is used to exit the program cleanly. Although this exception is not an error in the traditional sense, it can be caught using a try-except block if needed, especially when you want to prevent a script from terminating abruptly. This article explains how SystemExit works and how you can catch and handle it in Python programs. When Does SystemExit Occur? The SystemExit exception is raised when - You call sys.exit() function to exit the program. The Python interpreter is terminating due to a call ... Read More

1K+ Views
StopIteration Exception in Python The StopIteration exception in Python is raised to indicate that there are no more items left in an iterator to retrieve. It occurs when a call to the next() or, __next__() reaches the end of an iterable. In this article, you will learn how and when StopIteration is raised, and how to catch and handle it using try-except blocks. When Does StopIteration Occur? When can retrieve the contents of an Iterator object, using the Python built-in function next() or the __next__() method (of the iterator object). The next() function internally calls the _next__() method. These methods return the ... Read More

487 Views
StandardError in Python 2In Python 2, StandardError was a built-in exception class that is a base class for all built-in exceptions except for SystemExit, KeyboardInterrupt, and GeneratorExit. Using this class, we were able to catch the most common runtime errors in a single except block. However, since Python 3, the StandardError class has been deprecated, and now all built-in exceptions directly inherit from the Exception class. If you are using Python 3, you should catch exceptions using Exception instead of StandardError. Example Following is a basic example of raising the StandardError exception in Python 2 - try: value ... Read More

2K+ Views
Catching FloatingPointError Exception in PythonFloatingPointError in Python is an exception that occurs when there is an error in floating-point calculations. By default, Python does not raise this error for basic operations like dividing by zero; instead, it returns inf or nan. To catch this error, you need to enable it explicitly using the numpy module. In this article, you will learn how to catch a FloatingPointError by enabling it through NumPy settings and handling it using a try-except block. When Does FloatingPointError Occur? FloatingPointError can occur in cases like - Divide by zero in floating-point calculations (if enabled) ... Read More

539 Views
ZeroDivisionError Exception in Python The ZeroDivisionError is raised in Python when a number is divided by zero. Since dividing by zero is mathematically undefined, Python throws this error. In this article, you will learn how to catch and handle ZeroDivisionError using the try-except block. Usually, when an exception occurs, the program will be terminated abruptly, leaving the statements after the exception unexecuted. By handling this exception, the execution of the program continues even after the ZeroDivisionError exception (an invalid division attempt). The ZeroDivisionError generally occurs in the following cases - Dividing any number by zero using / ... Read More

344 Views
While passing arguments to a Python function, if the datatype of the given values is different from the function parameters, a TypeError is raised. But if the type of the argument is accurate and its value is inappropriate, a ValueError exception is raised In this article, you will learn how to catch ValueError exceptions using the general Exception class, which can catch all built-in exceptions, including ValueError. The ValueError exception commonly occurs when - You convert a string to an integer or float, but the string is not valid You pass an invalid value ... Read More

2K+ Views
LookupError in Python is the base class for errors that occur when a lookup using a key or index fails to find the expected value. This includes exceptions like IndexError and KeyError. If any lookup operation fails, a LookupError or one of its subclasses is raised. In this article, you will learn how to catch LookupError exceptions in Python and handle them to prevent your program from crashing abruptly. LookupError is commonly raised when - You access an invalid index in a list or a tuple. You use a missing key ... Read More