Use find() instead of index(), the former throws an exception on failure.