Learn Python
>>> exception_handling.builtin_exceptions

Built-in Exception Types in Python

#concept

Python ships with dozens of built-in exception types, each representing a specific, common category of problem. Recognizing the common ones on sight — what they mean and when they typically occur — makes both writing correct except clauses and reading a traceback much faster.

#how it works
1

Exception is the common ancestor to catch

Nearly every built-in exception a program should actually handle descends from it.

2

ValueError: right type, wrong value

Like int("abc") — a string, correctly, but not one that can be parsed as a number.

3

TypeError: the wrong type entirely

Like "2" + 2 — an operation applied to incompatible types.

4

KeyError and IndexError: missing lookups

A missing dictionary key, or an out-of-range sequence position, respectively.

5

A few more come up constantly

FileNotFoundError, ZeroDivisionError, and AttributeError round out the most frequently seen exceptions in everyday code.

#example
try:
int("abc")
except ValueError as e:
print("ValueError:", e)
 
try:
"2" + 2
except TypeError as e:
print("TypeError:", e)
 
try:
{"a": 1}["b"]
except KeyError as e:
print("KeyError:", e)
Output
ValueError: invalid literal for int() with base 10: 'abc'
TypeError: can only concatenate str (not "int") to str
KeyError: 'b'
1int("abc") raises ValueError, since "abc" is the right type (a string) but not a value that can be parsed as a number.
2"2" + 2 raises TypeError, since + can’t combine a string and an integer directly, regardless of their values.
3{"a": 1}["b"] raises KeyError, since the key "b" simply doesn’t exist in that dictionary.
#use cases
Writing an except clause that catches the exact, specific exception a piece of code might actually raise
Reading a traceback quickly by recognizing the exception type before even reading its message
Choosing between a handful of similar-looking exceptions when raising your own, like ValueError vs TypeError
Anticipating the most likely failure points in code that parses text, looks up dictionary keys, or does arithmetic

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.