What about a compromise of using a set/map container?  A little better performance than this linear search, and maintaining the safety.

On safety - what's the consequence of this occurring and not catching it?