# `KeyError` [🔗](https://github.com/elixir-lang/elixir/blob/v1.20.1/lib/elixir/lib/exception.ex#L2151) An exception raised when a key is not found in a data structure. For example, this is raised by `Map.fetch!/2` when the given key cannot be found in the given map: iex> map = %{name: "Alice", age: 25} iex> Map.fetch!(map, :first_name) ** (KeyError) key :first_name not found in: ... The following fields of this exception are public and can be accessed freely: * `:term` (`t:term/0`) - the data structure that was searched * `:key` (`t:term/0`) - the key that was not found --- *Consult [api-reference.md](api-reference.md) for complete listing*