I have code similar to this structure:
def my_gen(some_str):
if some_str == "":
raise StopIteration("Input was empty")
else:
parsed_list = parse_my_string(some_str)
for p in parsed_list:
x, y = p.split()
yield x, y
for x, y in my_gen()
# do stuff
# I want to capture the error message from StopIteration if it was raised manually
Is it possible to do this by using a for loop? I couldn't find a case similar to this elsewhere. If using a for loop isn't possible, what are some other alternatives?
Thanks