1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
# Indirectly makes sure the cleanup happens correctly on breaking.
def try_except_break():
"""
>>> print(try_except_break())
a
"""
for x in list("abc"):
try:
x()
except:
break
return x
def try_break_except():
"""
>>> print(try_break_except())
a
"""
for x in list("abc"):
try:
break
except:
pass
return x
def try_no_break_except_return():
"""
>>> print(try_no_break_except_return())
a
"""
for x in list("abc"):
try:
x()
break
except:
return x
return x
|