Built-in Exceptions

noun

say it: “BILT in ik-SEP-shunz” /ˈbɪlt ɪn ɪkˈsɛpʃənz/

The error types Python already has, such as ValueError for an unusable value, KeyError for a missing dictionary key and IndexError for a position past the end of a list.

What are Python's built-in exceptions?

Built-in exceptions are the error types Python already has, like ValueError (right type, wrong value), KeyError (missing dictionary key) and IndexError (position past the end of a list).

menu = {"tea": 3}
menu["coffee"]     # KeyError: 'coffee'

items = ["a", "b"]
items[5]           # IndexError: list index out of range

In a sentence

  • “Check the list of built-in exceptions before writing your own error type.”
  • “ValueError and KeyError are built-in exceptions: you don't define them, Python does.”

Level: Journeyman · More Python terms at this level

Updated