🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError. ... Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of NameError. ... Raised when a Unicode-related encoding or decoding error occurs.
🌐
Tutorial Teacher
tutorialsteacher.com › python › error-types-in-python
Error Types in Python
Learn about built-in error types in Python such as IndexError, NameError, KeyError, ImportError, etc.
People also ask

What is the most common error in Python?
For beginners, SyntaxError and IndentationError are the most frequent, since both come from formatting rather than logic. Among runtime exceptions, TypeError, NameError, and KeyError are the ones you meet most often in day-to-day code.
🌐
last9.io
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained ...
How do you find a logical error in Python?
Logical errors raise nothing, so the interpreter cannot help. Compare the output you got against the output you expected on a small input you can verify by hand, then narrow the gap with print statements, a debugger, or unit tests that assert the expected result. Code review is effective here because the bug is in the reasoning, not the syntax.
🌐
last9.io
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained ...
How many types of errors are there in Python?
Three: syntax errors, runtime errors, and logical errors. Every named exception, such as TypeError or KeyError, is a specific case that belongs to one of these three categories rather than a fourth type of its own.
🌐
last9.io
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained ...
🌐
Better Stack
betterstack.com › community › guides › scaling-python › python-errors
15 Common Errors in Python and How to Fix Them | Better Stack Community
Traceback (most recent call last): File "/home/stanley/code_samples/main.py", line 1, in <module> large_list = [0] * (10**9) # Attempting to create a list with more than a billion elements MemoryError · To handle this, use memory profiling tools like Scalene to pinpoint the memory-intensive parts of your program. For Python servers, an interim fix could be setting up an auto-restart mechanism that activates when memory usage crosses a certain limit.
🌐
W3Schools
w3schools.com › python › python_ref_exceptions.asp
Python Built-in Exceptions
The table below shows built-in exceptions that are usually raised in Python.
🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.7 documentation
The preceding part of the error message shows the context where the exception occurred, in the form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from standard input.
🌐
Rollbar
rollbar.com › home › what are the different types of python errors? – and how to handle them
What are the Different Types of Python Errors? – and How to Handle Them
Though we have discussed only 7 types of errors that are encountered frequently, the list doesn’t end here. There are many more built-in errors in Python, like KeyError , MemoryError , ImportError that you may encounter as you develop more complex applications..
Published: July 14, 2025
🌐
Programiz
programiz.com › python-programming › exceptions
Python Exceptions (With Examples)
There are plenty of built-in exceptions in Python that are raised when corresponding errors occur. We can view all the built-in exceptions using the built-in local() function as follows: ... Here, locals()['__builtins__'] will return a module of built-in exceptions, functions, and attributes and dir allows us to list ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › errors-and-exceptions-in-python
Errors and Exceptions in Python - GeeksforGeeks
May 29, 2026 - These errors are harder to find because no error message is shown. They usually happen due to wrong formulas, conditions or calculations. Example: In this example, the program calculates the average incorrectly because 1 is subtracted from the final result. Python · a = [10, 20, 30, 40, 50] b = 0 for i in a: b += i res = b / len(a) - 1 print(res) Output · 29.0 · Explanation: expected average of the list is 30, but the program prints 29.0.
Find elsewhere
🌐
Last9
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained | Last9
January 3, 2025 - IndexError: Raised when trying to access an index that is out of range in a list or tuple. KeyError: Raised when trying to access a key in a dictionary that doesn’t exist. ... In this example, if the user inputs anything other than a valid integer, a ValueError will be raised, and the program will handle it gracefully without crashing. ... For a deeper dive into OTLP headers and the OpenTelemetry Python SDK, check out our article on Whitespace in OTLP Headers and OpenTelemetry Python SDK.
🌐
Qodo
qodo.ai › blog › learn › common python error types and how to resolve them
Common Python error types and how to resolve them
March 20, 2025 - # Common IndexError trigger numbers = [1, 2, 3] print(numbers[4]) # IndexError: list index out of range # Empty list scenario empty_list = [] print(empty_list[0]) # Another IndexError case · To mitigate IndexErrors, it comes highly recommended to implement defensive programming practices. Standard strategies include prevalidating index values against sequence lengths, utilizing Python’s built-in safeguards, and implementing proper error handling:
🌐
Medium
medium.com › @techwithpraisejames › types-of-errors-in-python-and-how-to-handle-them-fe8616257b52
Common Types of Errors in Python and How to Handle Them | by Praise James | Medium
August 7, 2025 - You will typically get this error when the index you provide is out of the valid range for that particular sequence as shown below: numbers = [1, 2, 3, 4, 5] print(numbers[5]) #This will raise an IndexError since the valid indices for 'numbers' are 0, 1, 2, 3, and 4. ... This code attempts to access the element at index 5 in the list ‘numbers’, which is out of range. That’s why the code returned an IndexError. Remember that indexing in Python starts from 0.
Top answer
1 of 1
2

As expected, the official documentation has the answer.

On this page, you'll find the base exceptions, and the concrete exceptions as well, sorted by category. You'll find at section 5.4. Exception hierarchy an inheritance tree displaying the hierarchy between built-in exceptions.

The most interesting point certainly is that every exception extends BaseException, and that a custom exception should in most cases inherit from Exception.

Here is the exceptions hierarchy tree:

BaseException
 +-- SystemExit
 +-- KeyboardInterrupt
 +-- GeneratorExit
 +-- Exception
      +-- StopIteration
      +-- StopAsyncIteration
      +-- ArithmeticError
      |    +-- FloatingPointError
      |    +-- OverflowError
      |    +-- ZeroDivisionError
      +-- AssertionError
      +-- AttributeError
      +-- BufferError
      +-- EOFError
      +-- ImportError
      |    +-- ModuleNotFoundError
      +-- LookupError
      |    +-- IndexError
      |    +-- KeyError
      +-- MemoryError
      +-- NameError
      |    +-- UnboundLocalError
      +-- OSError
      |    +-- BlockingIOError
      |    +-- ChildProcessError
      |    +-- ConnectionError
      |    |    +-- BrokenPipeError
      |    |    +-- ConnectionAbortedError
      |    |    +-- ConnectionRefusedError
      |    |    +-- ConnectionResetError
      |    +-- FileExistsError
      |    +-- FileNotFoundError
      |    +-- InterruptedError
      |    +-- IsADirectoryError
      |    +-- NotADirectoryError
      |    +-- PermissionError
      |    +-- ProcessLookupError
      |    +-- TimeoutError
      +-- ReferenceError
      +-- RuntimeError
      |    +-- NotImplementedError
      |    +-- RecursionError
      +-- SyntaxError
      |    +-- IndentationError
      |         +-- TabError
      +-- SystemError
      +-- TypeError
      +-- ValueError
      |    +-- UnicodeError
      |         +-- UnicodeDecodeError
      |         +-- UnicodeEncodeError
      |         +-- UnicodeTranslateError
      +-- Warning
           +-- DeprecationWarning
           +-- PendingDeprecationWarning
           +-- RuntimeWarning
           +-- SyntaxWarning
           +-- UserWarning
           +-- FutureWarning
           +-- ImportWarning
           +-- UnicodeWarning
           +-- BytesWarning
           +-- ResourceWarning
🌐
Real Python
realpython.com › ref › builtin-exceptions
Python’s Built-in Exceptions (Reference) – Real Python
RuntimeError Indicates an error that doesn’t fall into any other category. StopAsyncIteration Signals the end of an asynchronous iteration. StopIteration Signals the end of an iteration. SyntaxError Occurs when the interpreter encounters a line of code that violates Python’s syntax rules.
🌐
SwCarpentry
swcarpentry.github.io › python-novice-inflammation › 09-errors.html
Programming with Python: Errors and Exceptions
April 21, 2023 - --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-7-3ad455d81842> in <module> 16 print_message(7) 17 ---> 18 print_sunday_message() 19 <ipython-input-7-3ad455d81842> in print_sunday_message() 14 15 def print_sunday_message(): ---> 16 print_message(7) 17 18 print_sunday_message() <ipython-input-7-3ad455d81842> in print_message(day) 11 'Aw, the weekend is almost over.' 12 ] ---> 13 print(messages[day]) 14 15 def print_sunday_message(): IndexError: list index out of range ... Newer versions of Python have improved error printouts.
🌐
Middleware
middleware.io › blog › python-error-types
Python Error Types: Common Errors and How to Handle Them
Discover common Python error types, what causes them, and how to handle them effectively to write cleaner, more reliable, and bug-free code.
🌐
Tutorialspoint
tutorialspoint.com › python › standard_exceptions.htm
Python Standard Exceptions
Here is a list all the standard Exceptions available in Python −
🌐
Toppr
toppr.com › guides › python-guide › tutorials › python-files › python-errors-and-built-in-exceptions
Python Errors and Built-in Exceptions | Different types of errors in Python |
October 21, 2021 - When a Python program meets an unhandled error, it terminates. A Python object that reflects an error is known as an exception. The different types of errors in Python can be broadly classified as below: Errors in syntax (Syntax Errors) Errors in logic (Logical Errors) (Exceptions)
Top answer
1 of 4
12

To amplify Messa, catch what you expect are failure modes that you know how to recover from. Ian Bicking wrote an article that addresses some of the overarching principles as does Eli Bendersky's note.

The problem with the sample code is that it is not handling errors, just prettifying them and discarding them. Your code does not "know" what to do with a NameError and there isn't much it should do other than pass it up, look at Bicking's re-raise if you feel you must add detail.

IOError and OSError are reasonably "expectable" for a shutil.move but not necessarily handleable. And the caller of your function wanted it to move a file and may itself break if that "contract" that Eli writes of is broken.

Catch what you can fix, adorn and re-raise what you expect but can't fix, and let the caller deal with what you didn't expect, even if the code that "deals" is seven levels up the stack in main.

2 of 4
5

Python doesn't have a mechanism right now for declaring which exceptions are thrown, unlike (for example) Java. (In Java you have to define exactly which exceptions are thrown by what, and if one of your utility methods needs to throw another exception then you need to add it to all of the methods which call it which gets boring quickly!)

So if you want to discover exactly which exceptions are thrown by any given bit of python then you need to examine the documentation and the source.

However python has a really good exception hierarchy.

If you study the exception hierarchy below you'll see that the error superclass you want to catch is called StandardError - this should catch all the errors that might be generated in normal operations. Turning the error into into a string will give a reasonable idea to the user as to what went wrong, so I'd suggest your code above should look like

from shutil import move
try:
    move('somefile.txt', '/tmp/somefile.txt')
except StandardError, e:
    print 'Move failed: %s' % e

Exception hierarchy

BaseException
|---Exception
|---|---StandardError
|---|---|---ArithmeticError
|---|---|---|---FloatingPointError
|---|---|---|---OverflowError
|---|---|---|---ZeroDivisionError
|---|---|---AssertionError
|---|---|---AttributeError
|---|---|---BufferError
|---|---|---EOFError
|---|---|---EnvironmentError
|---|---|---|---IOError
|---|---|---|---OSError
|---|---|---ImportError
|---|---|---LookupError
|---|---|---|---IndexError
|---|---|---|---KeyError
|---|---|---MemoryError
|---|---|---NameError
|---|---|---|---UnboundLocalError
|---|---|---ReferenceError
|---|---|---RuntimeError
|---|---|---|---NotImplementedError
|---|---|---SyntaxError
|---|---|---|---IndentationError
|---|---|---|---|---TabError
|---|---|---SystemError
|---|---|---TypeError
|---|---|---ValueError
|---|---|---|---UnicodeError
|---|---|---|---|---UnicodeDecodeError
|---|---|---|---|---UnicodeEncodeError
|---|---|---|---|---UnicodeTranslateError
|---|---StopIteration
|---|---Warning
|---|---|---BytesWarning
|---|---|---DeprecationWarning
|---|---|---FutureWarning
|---|---|---ImportWarning
|---|---|---PendingDeprecationWarning
|---|---|---RuntimeWarning
|---|---|---SyntaxWarning
|---|---|---UnicodeWarning
|---|---|---UserWarning
|---GeneratorExit
|---KeyboardInterrupt
|---SystemExit

This also means that when defining your own exceptions you should base them off StandardError not Exception.

Base class for all standard Python exceptions that do not represent
interpreter exiting.
🌐
Anenadic
anenadic.github.io › 2014-11-10-manchester › novice › python › 07-errors.html
Python errors and exceptions
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-1-9d0462a5b07c> in <module>() 1 from errors_01 import favorite_ice_cream ----> 2 favorite_ice_cream() /Users/jhamrick/project/swc/novice/python/errors_01.pyc in favorite_ice_cream() 5 "strawberry" 6 ] ----> 7 print ice_creams[3] IndexError: list index out of range