stop_if_not_in_element_range function

Raise error if element index is outside of range or element name is unknown