I want to exception handle ‘list index out of range.’

Handling the exception is the way to go:

try:
    gotdata = dlist[1]
except IndexError:
    gotdata="null"

Of course you could also check the len() of dlist; but handling the exception is more intuitive.

Leave a Comment