I tried running these two code snippets
try:
dict(yyy) # yyy is not a variable
except Exception as e:
print('ok')
this prints ok as expected.
But then I ran this code
try:
dict(2 = yyy)
except Exception as e:
print('ok')
This raises an exception SyntaxError: keyword can't be an expression
But I am catching it and printing ok instead - but it still raises this exception.
So my question is why am I able to cleanly catch an exception in the first code block but not the second code block?