[Python-ideas] try-else without except or finally

Rob Cliffe rob.cliffe at btinternet.com
Thu Nov 10 09:38:14 CET 2011


Omitting the except clause would make the code more obscure.
'else' means the second of two alternatives.  Omitting the first 
alternative altogether obfuscates the code and makes it look as if the 
first alternative is the try block, i.e. it suggests if anything that 
the code following 'else:' is executed when there is an exception rather 
than when there isn't.
-1 from me
Rob Cliffe

On 10/11/2011 08:10, Matt Joiner wrote:
> Hi Ideas,
>
> I frequently find myself in the following situations:
>
> 1) I wish to do something if no exception is thrown, for instance:
>
>          try:
>              logger.debug('Fiber starting: %s', self)
>              try:
>                  self._result = self._routine()
>              finally:
>                  logger.debug('Fiber finished: %s', self)
>          except:
>              raise
>          else:
>              raise FiberExit(self)
>          finally:
>              self._finished.set()
>              unregister_fiber(self)
>
> Here it's sufficient that that if an exception is already present, I
> don't need to raise another. The except clause is clearly pointless.
> 2) I'm experimenting with catching various exceptions and remove the
> last except clause. I need to put a finally: pass; to avoid having to
> restructure all my code, since this is currently the only way to
> maintain the try-except-else-finally statement without catching dummy
> exceptions.
>
> I propose that the except clause be optional.
>
> Cheers,
> Matt
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list