-2

normal:

try:
    something may go wrong...
except:
    pass
else:
    others func...

what i need:

try:
    something may go wrong...
else:
    others func...

Are there some reasons for 'try...else' not exists?

overflow
  • 87
  • 1
  • 1
  • 7
  • What should supposedly happen in your `try...else` example? do you mean `try...finally`? – DeepSpace Mar 17 '19 at 13:17
  • @DeepSpace When any wrong not happened, I want to execute the else block. But try...finally will always be executed. – overflow Mar 17 '19 at 13:22
  • What's wrong with `except: pass`? It's just 12 characters, no harm in typing it. :P It also makes the code more readable (e.g. "Here, I will pass the exception..."). – TrebledJ Mar 17 '19 at 13:25
  • And what should happen when something wrong **does** happen? The Python motto says "explicit is better than implicit". If you want to ignore an exception you must explicitly say so. – DeepSpace Mar 17 '19 at 13:28
  • 1
    @TrebuchetMS hh, ok, i got it. :D – overflow Mar 17 '19 at 13:30

1 Answers1

0

If it was supported, the syntax

try:
    something may go wrong...
else:
    others func...

would be exactly equivalent in behaviour to

something may go wrong...
others func...

i.e. you do not need any special syntax for it