🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Changed in version 3.5: Python now retries system calls when a syscall is interrupted by a signal, except if the signal handler raises an exception (see PEP 475 for the rationale), instead of raising InterruptedError. ... Raised when a file operation (such as os.remove()) is requested on a directory. Corresponds to errno EISDIR. ... Raised when a directory operation (such as os.listdir()) is requested on something which is not a directory.
🌐
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.
🌐
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 ...
🌐
Real Python
realpython.com › ref › builtin-exceptions
Python’s Built-in Exceptions (Reference) – Real Python
When something goes wrong during program execution, Python raises (or “throws”) an appropriate exception, which can be “caught” and handled using try…except blocks.
🌐
Runestone Academy
runestone.academy › ns › books › published › fopp › Exceptions › standard-exceptions.html
19.4. Standard Exceptions — Foundations of Python Programming
BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception +-- StopIteration +-- StopAsyncIteration +-- ArithmeticError | +-- FloatingPointError | +-- OverflowError | +-- ZeroDivisionError +-- AssertionError +-- AttributeError +-- BufferError +-- EOFError +-- ImportError +-- LookupError | +-- IndexError | +-- KeyError +-- MemoryError +-- NameError | +-- UnboundLocalError +-- OSError | +-- BlockingIOError | +-- ChildProcessError | +-- ConnectionError | | +-- BrokenPipeError | | +-- ConnectionAbortedError | | +-- ConnectionRefusedError | | +-- ConnectionResetError | +-- F
🌐
Medium
medium.com › @sandeepkothari › a-comprehensive-list-of-python-exceptions-a-must-read-for-python-programmers-3f4dd24f3b11
A comprehensive list of Python exceptions — a must read for python programmers | by Sandeep Kothari | Medium
September 7, 2024 - Arithmetic Exceptions ZeroDivisionError: Raised when division or modulo by zero is attempted. OverflowError: Raised when the result of an arithmetic operation is too large to be represented.
🌐
GeeksforGeeks
geeksforgeeks.org › python › built-exceptions-python
Python Built-in Exceptions - GeeksforGeeks
Python · my_list = [1, 2, 3] try: element = my_list[5] except IndexError as e: print(e) Output · list index out of range · Explanation: list has only indices 0, 1, 2. When we try to access index 5, Python raises an IndexError. KeyError occurs when you try to access a dictionary key that doesn’t exist.
Published: April 18, 2026
🌐
Tutorialspoint
tutorialspoint.com › python › standard_exceptions.htm
Python Standard Exceptions
Here is a list all the standard Exceptions available in Python −
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › exception-handling-python
Exception & Error Handling in Python | Tutorial by DataCamp | DataCamp
May 29, 2026 - With exception groups, nested exceptions are now easier to debug and handle, especially in complex workflows like multiprocessing or asynchronous tasks. Python 3.12 continued a long-running effort to make error messages more specific and actionable. For example, NameError messages now suggest similarly-named variables that are in scope, and attribute errors on common types give more targeted hints: # Python 3.12+ my_list = [1, 2, 3] my_list.appendd(4)
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.
🌐
Real Python
realpython.com › python-built-in-exceptions
Python's Built-in Exceptions: A Walkthrough With Examples – Real Python
March 18, 2026 - As you already know, you’ll find many built-in exceptions in Python. You can explore them by inspecting the builtins namespace from a REPL session: ... >>> import builtins >>> dir(builtins) [ 'ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', ... ] In this example, you first import the builtins namespace. Then, you use the built-in dir() function to list ...
🌐
Dataquest
dataquest.io › home › blog › python exceptions: the ultimate beginner's guide (with examples)
Python Exceptions: The Ultimate Beginner's Guide (with Examples)
March 6, 2023 - The parser shows the place where the syntax error was detected by a little arrow ^. Notice also that the subsequent line print(1) was not executed since the Python interpreter stopped working when the error occurred. ... --------------------------------------------------------------------------- NameError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_4732/971139432.py in <module> ----> 1 print(x) 2 print(1) NameError: name 'x' is not defined · Now when we have fixed the wrong syntax, we got another type of error: an exception.
🌐
Tutorialspoint
tutorialspoint.com › python › python_builtin_exceptions.htm
Python - Built-in Exceptions
Built-in exceptions are pre-defined error classes in Python that handle errors and exceptional conditions in programs. They are derived from the base class "BaseException" and are part of the standard library. Here is a list of Standard Exceptions available in Python −
🌐
Python Tutorial
pythontutorial.net › home › python oop › python exceptions
Python Exceptions
March 28, 2025 - This page shows a complete class hierarchy for built-in exceptions in Python. The following example defines a list of three elements and attempts to access the fourth one:
Top answer
1 of 4
15

If the error matches the description of one of the standard python exception classes, then by all means throw it.

Common ones to use are TypeError and ValueError, the list you linked to already is the standard list.

If you want to have application specific ones, then subclassing Exception or one of it's descendants is the way to go.

To reference the examples you gave from .NET ApplicationException is closest to RuntimeError ArgumentNullException will probably be an AttributeError (try and call the method you want, let python raise the exception a la duck typing) AttributeOutOfRange is just a more specific ValueError InvalidOperationException could be any number of roughly equivalent exceptions form the python standard lib.

Basically, pick one that reflects whatever error it is you're raising based on the descriptions from the http://docs.python.org/library/exceptions.html page.

2 of 4
14

First, Python raises standard exceptions for you.

It's better to ask forgiveness than to ask permission

Simply attempt the operation and let Python raise the exception. Don't bracket everything with if would_not_work(): raise Exception. Never worth writing. Python already does this in all cases.

If you think you need to raise a standard exception, you're probably writing too much code.

You may have to raise ValueError.

def someFunction( arg1 ):
    if arg1 <= 0.0:
        raise ValueError( "Guess Again." )

Once in a while, you might need to raise a TypeError, but it's rare.

def someFunctionWithConstraints( arg1 ):
    if isinstance(arg1,float):
         raise TypeError( "Can't work with float and can't convert to int, either" )
    etc.

Second, you almost always want to create your own, unique exceptions.

 class MyException( Exception ): 
     pass

That's all it takes to create something distinctive and unique to your application.

🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › python › python_exceptions.htm
Python - Exceptions Handling
In Python, exceptions are raised when errors or unexpected situations arise during program execution, such as division by zero, trying to access a file that does not exist, or attempting to perform an operation on incompatible data types.
🌐
LearnPython.com
learnpython.com › blog › python-exceptions
A Brief Guide to Python Exceptions | LearnPython.com
October 29, 2022 - The exception message might look scary, but it’s actually very informative. It tells us: What type of Python exception was raised (in this case, a ValueError).
🌐
CodeRivers
coderivers.org › blog › python-exception-list
Python Exception List: A Comprehensive Guide - CodeRivers
February 22, 2026 - # This code will raise a TypeError my_list = [1, 2, 3] result = my_list + "not a list" You can raise an exception in Python using the raise keyword. This is useful when you want to signal that something has gone wrong in your code.