🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3999

Re: sample auto_ptr template

#3999
From: Fergus Henderson
Date: Fri, 12 Apr 1996 12:47
51 lines
2472 bytes
ajay@lehman.com (Ajay Kamdar) writes:

>The following example demonstrates why allowing exceptions to
>propogate out of destructors is more trouble than it is worth:
>
>   auto_ptr<X>  get_X()
>   {
>      auto_ptr<X> p    = new X;
>      auto_ptr<X> temp = new X;
>      BadIdea     b1; // throws an exception in dtor
>      BadIdea     b2; // throws an exception in dtor
>
>      // ... stuff
>
>      return p;
>   }
>
>When b2 is destructed, it throws an exception. So what happens
>next?
>
>Does the run time system try to continue to destruct b1, temp,
>and p?

Yes.

>If it does, b1's destructor is also going to thow an
>exception. If I interpret 15.5.1 in theApril '95 CD correctly
>(I don't have access to any later drafts), terminate() is called
>because of the exception propagating out of b1's destructor.

That's right.  I'm pretty sure this hasn't changed in the more recent drafts.

>If on the other hand the run time system abandons executing
>the other destuctors in get_X() after b2's destructor has
>thrown an exception,

Such an implementation would not be conforming.

(Incidentally, I agree quite strongly with the arguments voiced by
Ajay Kamdar in this thread.)

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <fjh-960412-224718@cs.mu.oz.au>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <009A04DA6A831C40.49800EAC@ittpub.nl> <bill-0504961003150001@bgibbons.vip.best.com> <4k4noe$igl@jabba.lehman.com> <KANZE.96Apr9115532@gabi.gabi-soft.fr> <4kjqam$qs6@jabba.lehman.com>

Show Full Headers
Complete Article Headers
From: Fergus Henderson <fjh@cs.mu.oz.au>
Message-ID: <fjh-960412-224718@cs.mu.oz.au>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 12 Apr 96 12:47:18 GMT
Approved: fjh@cs.mu.oz.au
Organization: -
Newsgroups: comp.std.c++
Subject: Re: sample auto_ptr template
References: <009A04DA6A831C40.49800EAC@ittpub.nl> <bill-0504961003150001@bgibbons.vip.best.com> <4k4noe$igl@jabba.lehman.com> <KANZE.96Apr9115532@gabi.gabi-soft.fr> <4kjqam$qs6@jabba.lehman.com>
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMW5Q9+EDnX0m9pzZAQGAdgF8DQU6nXgSWckQyauk2lgEZXBxCRFb4Bss
 x48FnVo8jCWgkSzLg5XP47S5R9zqYw5c
 =5KjL