[Python-ideas] try-else without except or finally
Matt Joiner
anacrolix at gmail.com
Thu Nov 10 09:10:04 CET 2011
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
More information about the Python-ideas
mailing list