हम कोड में एक्सेप्शन को निम्न प्रकार से फिर से लिखकर हैंडल कर सकते हैं:
a = []
foo = 'redbullz'
try:
for i in foo:
a.append(i)
print(a[8])
except Exception as e:
print(e)
हमें निम्न आउटपुट मिलता है:
list index out of range Process finished with exit code 0