Article View: comp.std.c++
Article #4001Re: sample auto_ptr template
From: Fergus Henderson
Date: Fri, 12 Apr 1996 12:46
Date: Fri, 12 Apr 1996 12:46
51 lines
2517 bytes
2517 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-224606@cs.mu.oz.au>Path:
arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-backReferences:
<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
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: sample auto_ptr template Date: 12 Apr 96 12:46:05 GMT Organization: - Approved: fjh@cs.mu.oz.au Message-ID: <fjh-960412-224606@cs.mu.oz.au> 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> NNTP-Posting-Host: munta.cs.mu.oz.au X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMW5Qs+EDnX0m9pzZAQFF9wF9Gr8cS6QZpV64YO/IKiifEKvAYOCworxK rLEofBETnXvWMqJe6KBncEvPSrVHKs+7 =iJo9