# coding=UTF-8
def lost_exception():
while True:
try:
print("hello world")
raise IndexError("rrr")
except NameError as e:
print 'NameError happened'
print e
finally:
# IndexError is saved for reraise
# but it won't reraise if
# 1. new excepton happens in finally
# 2. return
# 3. break
print("finally executed")
break
def false_return(n):
try:
if n <= 0:
raise ValueError("n must > 0")
else:
# return in finally gets executed first
return n
except ValueError as e:
print("ValueError")
print e
finally:
print("in finally")
return -1
def main():
# lost_exception()
print(false_return(-100))
print(false_return(10))
if __name__ == "__main__":
main()