I have a list of lists
x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
I want the code to throw an Array Out of Bounds Exception, similar to how it is done in Java when the index is out of range. For instance,
x[0][0] # 1 x[0][1] # 2 x[0-1][0-1] # <--- this returns 9 but I want it to throw an exception x[0-1][1] # <--- this returns 7 but again I want it to throw an exception x[0][2] # this throws an index out of range exception, as it should
If an exception is thrown, I want it to return 0.
try: x[0-1][0-1] # I want this to throw an exception except: print 0 # prints the integer 0
I think that, in principle, when the index is negative, throw an exception.
source share