2 ms·
Another weird syntax quirk is this: e = 4 try: b = 4/0 except Exception as e: print("exception raised") print(e) # NameError:
by remram 3y ago
Another weird syntax quirk is this:
e = 4
try:
b = 4/0
except Exception as e:
print("exception raised")
print(e) # NameError: name 'e' is not defined
The captured exception only exists in the 'except:' block, but instead of creating a new scope (shadowing the outer 'e'), it deletes it afterwards.