I found Python throwing a SyntaxError at me for trying try without except:
try:
spam()
else:
eggs()
finally:
semprini()
Instead, I was forced to write:
try:
spam()
except:
raise
else:
eggs()
finally:
semprini()
which felt slightly silly, but I want eggs() to be executed before semprini() — if I put the contents of the else:-clause after the finally:-clause it will be executed after semprini(). Although there has been a try without except proposal in the past, the semantics were different as there the implication was except: pass, i.e. the polar opposite of what I'm after. Interestingly, try: without either except: or else: is valid, but I can't have else: if I don't also have except:. Although there may be a different way to formulate the same, the alternatives I've thought of (probably) have subtly different behaviour.
Why does the presence of else: require the presence of except:?