A Tsang A Tsang - 9 days ago 6
Python Question

How to create custom error handling in python?

i = 0
numbers = ["1","1","1","1","1"]
while 0 == 0:
print(numbers[i])
i+=1


Once finished it would say out of index/range. How would I get it to say ran out of numbers instead of an error?

I think it's called error handling.

Answer

You can handle errors using try and except

try:
   print(numbers[i])
except Exception:
   print("ran out of numbers")