KeyError exception (Elixir v1.19.0-dev)

View Source

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: %{name: "Alice", age: 25}

The following fields of this exception are public and can be accessed freely:

  • :term (term/0) - the data structure that was searched
  • :key (term/0) - the key that was not found