I frequently find myself in the following situations

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 https://www.assortlist.com

On Tue, Oct 20, 2020 at 11:43 PM <71f13rvj@powerencry.com> 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.
Why not just put the raise FiberExit into the body of the try? ChrisA
participants (2)
-
71f13rvj@powerencry.com
-
Chris Angelico