Sarika Singh has Published 189 Articles

How to catch ValueError using Exception in Python?

Sarika Singh

Sarika Singh

Updated on 07-Jun-2025 19:10:08

360 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 ... Read More

How to catch ZeroDivisionError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 07-Jun-2025 18:13:43

581 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 ... Read More

How to catch StandardError Exception in Python?\\\

Sarika Singh

Sarika Singh

Updated on 07-Jun-2025 17:48:24

519 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 ... Read More

How to catch StopIteration Exception in Python?

Sarika Singh

Sarika Singh

Updated on 07-Jun-2025 17:15:16

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 ... Read More

How to catch a thread\\'s exception in the caller thread in Python?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:39:16

894 Views

Python threads do not automatically pass exceptions to the caller thread. To catch thread exceptions in the main thread, you can use custom thread classes, the ThreadPoolExecutor with futures, or a shared queue. Using a Wrapper with threading.Thread The easiest way to catch exceptions in a thread is to ... Read More

How to rethrow Python exception with new type?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:37:30

266 Views

In Python, you can catch an exception and raise a new one, while keeping the original exception for more details. This helps when you want to change a low-level error into a clearer, higher-level error that fits your application better. Sometimes, catching a specific exception and raising a new ... Read More

How to handle Python exception in Threads?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:35:09

1K+ Views

Python allows you to run multiple tasks at the same time using threads. However, handling exceptions in threads can be tricky because exceptions that happen inside a thread don't get passed to the main thread by default. To deal with this, you can catch errors inside the thread's function or ... Read More

How to catch OSError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:30:21

890 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 ... Read More

How to handle python exception inside if statement?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:28:41

3K+ Views

You cannot directly use an if statement to catch exceptions in Python. Instead, use a try-except block and place if conditions inside the except to respond differently based on the type or message of the exception. This allows you to write conditional logic for exception handling. Using if Inside the ... Read More

How to catch NotImplementedError Exception in Python?

Sarika Singh

Sarika Singh

Updated on 02-Jun-2025 15:25:44

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 ... Read More

Previous 1 ... 3 4 5 6 7 ... 19 Next
Advertisements