I've been breaking my head all day, and I cannot seem to solve this. I'm supposed to write an Exception class then raise it during an iteration and continue where I left off.
class OhNoNotTrueException(Exception):
"""Exception raised when False is encountered
Attributes:
message -- explanation of the error"""
def __init__(self, value):
self.value = value
am_i_true_or_false = [True, None, False, "True", 0, "", 8, "False", "True", "0.0"]
try:
for i in am_i_true_or_false:
if i is False:
raise OhNoNotTrueException(i)
continue #<--this continue does not work
else:
print(i, "is True")
except OhNoNotTrueException as e:
print(e.value, "is False")
However, I can't get the iteration back to the last index, even after putting continue. I'm not sure if this is the only way to do it, but I'm breaking my head over here. Anyone want to take a crack at it?
I'm supposed to get the following output:
True is true.
None is false
False is false
True is true.
0 is false
is false
8 is true.
False is true.
True is true.
0.0 is true.