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

Dennis Kaarsemaker dennis.kaarsemaker at booking.com
Thu Nov 10 10:12:59 CET 2011


On Thu, 2011-11-10 at 19:10 +1100, 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:

How is this...

>         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)

different from this...

        try:
            logger.debug('Fiber starting: %s', self)
            try:
                self._result = self._routine()
            finally:
                logger.debug('Fiber finished: %s', self)
            raise FiberExit(self)
        finally:
            self._finished.set()
            unregister_fiber(self)

That should do exactly what you want, shouldn't it?
-- 
Dennis Kaarsemaker         Senior Unix System Administrator
Amsterdam, The Netherlands   dennis.kaarsemaker at booking.com
http://www.booking.com           tel external +3120715 3409
                                    tel internal (7207)3409





More information about the Python-ideas mailing list