🌐
Python
docs.python.org β€Ί 3 β€Ί builtins β€Ί exceptions.html
Built-in Exceptions β€” Python 3.14.7 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which it is derived).
🌐
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
BaseException is the common base class of all exceptions. One of its subclasses, Exception, is the base class of all the non-fatal exceptions. Exceptions which are not subclasses of Exception are not typically handled, because they are used ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί built-exceptions-python
Python Built-in Exceptions - GeeksforGeeks
December 18, 2024 - Here’s a table listing all the major Python built-in exceptions along with a brief : ... The base class for all built-in exceptions. Example: ... Explanation: This code manually raises a BaseException and catches it, printing the exception message.
🌐
Python
docs.python.org β€Ί 3.3 β€Ί library β€Ί exceptions.html
5. Built-in Exceptions β€” Python 3.3.7 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which it is derived).
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί exceptions.html
Built-in Exceptions β€” Python 3.14.6 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any excep...
🌐
TutorialsPoint
tutorialspoint.com β€Ί python-exception-base-classes
Exception and Exception Classes
You can create a custom exception class by Extending BaseException class or subclass of BaseException. From above diagram we can see most of the exception classes in Python extends from the BaseException class.
🌐
Python Tutorial
pythontutorial.net β€Ί home β€Ί python oop β€Ί python exceptions
Python Exceptions
March 28, 2025 - In Python, exceptions are objects of the exception classes. All exception classes are the subclasses of the BaseException class.
🌐
Profound Academy
profound.academy β€Ί python-mid β€Ί exception-hierarchy-phonbKOpXJ362GhumAsG
Exception Hierarchy β€’ Intermediate Python
January 20, 2025 - The hierarchy of built-in exception classes in Python (from the official Python docs). This means that the FileNotFoundError is a subclass of an OSError, which is a subclass of the Exception class, which itself inherits from the BaseException.
Find elsewhere
🌐
Python
docs.python.org β€Ί 3.15 β€Ί library β€Ί exceptions.html
Built-in Exceptions β€” Python 3.15.0rc1 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any excep...
🌐
Medium
martinxpn.medium.com β€Ί exception-hierarchy-python-58-100-days-of-python-9d8585e6569b
Exception Hierarchy Python (58/100 Days of Python) | by Martin Mirakyan | Medium
April 10, 2023 - The following diagram shows the hierarchy of built-in exception classes in Python (taken from the official Python documentation): BaseException β”œβ”€β”€ BaseExceptionGroup β”œβ”€β”€ GeneratorExit β”œβ”€β”€ KeyboardInterrupt β”œβ”€β”€ SystemExit └── Exception β”œβ”€β”€ ArithmeticError β”‚ β”œβ”€β”€ FloatingPointError β”‚ β”œβ”€β”€ OverflowError β”‚ └── ZeroDivisionError β”œβ”€β”€ AssertionError β”œβ”€β”€ AttributeError β”œβ”€β”€ BufferError β”œβ”€β”€ EOFError β”œβ”€β”€ ExceptionGroup [BaseExceptionGroup] β”œβ”€β”€ ImportError β”‚ └── ModuleNotFoundError β”œβ”€β”€ LookupError
🌐
LinkedIn
linkedin.com β€Ί pulse β€Ί advanced-exception-handling-python-understanding-atexit-moonhee-lee-ezwrc
Advanced Exception Handling in Python: Understanding BaseException, atexit, and Beyond
February 28, 2024 - BaseException sits at the top of Python's exception hierarchy, acting as the base class for all exceptions, including system-exiting exceptions and errors.
🌐
jd:/dev/blog
julien.danjou.info β€Ί home β€Ί blog β€Ί the definitive guide to python exceptions
The definitive guide to Python exceptions β€” jd:/dev/blog
August 11, 2016 - Therefore, the message to display ... exceptions can be raised in any part of the program. The basic exception is called Exception and can be used anywhere in your program....
Top answer
1 of 2
50

The accepted answer is incorrect incomplete (at least for Python 3.6 and above).

By catching Exception you catch most errors - basically all the errors that any module you use might throw.

By catching BaseException, in addition to all the above exceptions, you also catch exceptions of the types SystemExit, KeyboardInterrupt, and GeneratorExit.

By catching KeyboardInterrupt, for example, you may stop your code from exiting after an initiated exit by the user (like pressing ^C in the console, or stopping launched application on some interpreters). This could be a wanted behavior (for example - to log an exit), but should be used with extreme care!

In the above example, by catching BaseException, you may cause your application to hang when you want it to exit.

2 of 2
39

Practically speaking, there is no difference between except: and except BaseException:, for any current Python release.

That's because you can't just raise any type of object as an exception. The raise statement explicitly disallows raising anything else:

[...] raise evaluates the first expression as the exception object. It must be either a subclass or an instance of BaseException.

Bold emphasis mine. This has not always been the case however, in older Python releases (2.4 and before) you could use strings as exceptions too.

The advantage then is that you get to have easy access to the caught exception. In order to be able to add as targetname, you must catch a specific class of exceptions, and only BaseException is going to do that.

You can still access the currently active exception by using sys.exc_info() though:

except:
    be = sys.exc_info()[1] 

Pick what you feel is more readable for your future self and for your colleagues.

🌐
w3resource
w3resource.com β€Ί python β€Ί certificate β€Ί functions-and-exceptions-base-exception.php
PCEP Practice Test: Python BaseException Hierarchy
September 19, 2024 - Question 1: What is the base class for all built-in exceptions in Python? ... Explanation: BaseException is the topmost class in Python’s built-in exception hierarchy from which all other exceptions are derived.
🌐
Real Python
realpython.com β€Ί python-built-in-exceptions
Python's Built-in Exceptions: A Walkthrough With Examples – Real Python
March 18, 2026 - In this tutorial, you'll get to know some of the most commonly used built-in exceptions in Python. You'll learn when these exceptions can appear in your code and how to handle them.
🌐
University of New Brunswick
cs.unb.ca β€Ί ~bremner β€Ί teaching β€Ί cs2613 β€Ί books β€Ί python3-doc β€Ί library β€Ί exceptions.html
Built-in Exceptions β€” Python 3.9.2 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which it is derived).