From the python docs

Note: for loops expect that an IndexError will be raised for illegal indexes to allow proper detection of the end of the sequence.

So how about catching the file not found error and raising an index error instead.
try:
    im=Image.open(img_name)
except FileNotFoundError:
    raise IndexError