python - Why is try-finally valid, but not try-else-finally? -


i found python throwing syntaxerror @ me trying try without except:

try:     spam() else:     eggs() finally:     semprini() 

instead, forced write:

try:     spam() except:     raise else:     eggs() finally:     semprini() 

which felt silly, want eggs() executed before semprini() — if put contents of else:-clause after finally:-clause executed after semprini(). although there has been try without except proposal in past, semantics different there implication except: pass, i.e. polar opposite of i'm after. interestingly, try: without either except: or else: is valid, can't have else: if don't have except:. although there may different way formulate same, alternatives i've thought of (probably) have subtly different behaviour.

why presence of else: require presence of except:?

you should have written

try:     spam()     eggs() finally:     semprini() 

in absence of except clauses, else useless.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -