Earlier today I read about this strange case in Python, Javaand JS:
try:
return True
finally:
return False
What returns False.
So, I decided to play with him:
def caseThree():
try:
caseThree()
except:
print("Error")
caseThree()
finally:
return False
print(caseThree())
In Python, 2.7this returns:
Error
False
However in Python 3.5:
Error
Fatal Python error: Cannot recover from stack overflow.
Current thread 0x000025ec (most recent call first):
File "`<stdin>`", line 3 in caseThree
the last line is repeated until you get: ...
Can someone explain why the code 2.7does not overflow the stack, but 3.5does?
source
share