RFC: Proposal: Deterministic Object Destruction

Ooomzay ooomzay at gmail.com
Mon Mar 5 10:08:01 EST 2018


On Monday, 5 March 2018 14:36:30 UTC, Chris Angelico  wrote:
> On Tue, Mar 6, 2018 at 1:25 AM, Ooomzay wrote:
> > Ahah... I see now you are running it from a shell so the exception is staying in scope. We just need to include normal exception handling in the example to fix this:-
> >
> > def main():
> >     try:
> >         c = C()
> >         c.dostuff()
> >     except:
> >         print("Boom!")
> >
> > main()
> >
> 
> So RAII depends on absorbing every exception close to where the
> resource is being managed? You can't permit that exception to bubble
> up lest the resource get leaked??

The exception can bubble up as many layers as you like but in python the 
exception leaks out of the handling context and needs its scope limiting. I have previously pointed out that such scoping is still recommended and that a function is pythons scoping construct - so use them for the job.



More information about the Python-list mailing list