Some text some message..
Back 🌳 The Error Family Tree in Python 01 Sep, 2025

At the top of the family we have:

🔹 BaseException

This is the super parent of all exceptions (errors) in Python.
Every other error comes from this.


🔹 Direct children of BaseException

These are special system-level exceptions (not used often by normal programmers):

  1. SystemExit → Raised when sys.exit() is called (to exit program).

  2. KeyboardInterrupt → Raised when you press Ctrl + C to stop program.

  3. GeneratorExit → Raised when a generator is closed.

  4. Exception → The main parent of all “normal” errors (like ValueError, TypeError).

👉 As a programmer, you usually handle Exception and its children, not the other three.


🔹 Children of Exception (common ones)

These are the errors you see every day:

  • Arithmetic Errors

    • ZeroDivisionError (divide by zero)

    • OverflowError (number too big)

    • FloatingPointError (rare floating-point issues)

  • Lookup Errors

    • IndexError (list index out of range)

    • KeyError (dict key missing)

  • Type and Value Errors

    • TypeError (wrong data type, e.g., "5" + 2)

    • ValueError (right type but wrong value, e.g., int("abc"))

  • Import Errors

    • ImportError (module can’t be imported)

    • ModuleNotFoundError (module doesn’t exist)

  • File and OS Errors

    • FileNotFoundError (file missing)

    • PermissionError (no access rights)

    • OSError (general system-related errors)

  • Others

    • AttributeError (attribute doesn’t exist)

    • NameError (variable not defined)

    • RuntimeError (general error during runtime)

    • NotImplementedError (something is not yet implemented)


🌎 Layman Analogy

Think of it like a family tree 👪:

  • BaseException → Great-Grandparent 👴

  • Exception → Parent 👨

  • TypeError, ValueError, ZeroDivisionError, FileNotFoundError… → Kids 👦👧

So whenever you write:

except Exception:
    # handle error

👉 You’re catching all the kids (common errors) but not the great-grandparent (BaseException special ones like SystemExit, KeyboardInterrupt).


🖼 Visual Tree (Simplified)

BaseException
 ├── SystemExit
 ├── KeyboardInterrupt
 ├── GeneratorExit
 └── Exception
      ├── ArithmeticError
      │    ├── ZeroDivisionError
      │    ├── OverflowError
      │    └── FloatingPointError
      ├── LookupError
      │    ├── IndexError
      │    └── KeyError
      ├── ImportError
      │    └── ModuleNotFoundError
      ├── OSError
      │    ├── FileNotFoundError
      │    ├── PermissionError
      │    └── TimeoutError
      ├── ValueError
      │    └── UnicodeError
      ├── TypeError
      ├── AttributeError
      ├── NameError
      ├── RuntimeError
      └── ...

✅ So, in short:

  • BaseException = All errors.

  • Exception = Normal errors you usually deal with.

  • Children of Exception = Specific everyday errors.