Article View: comp.std.c++
Article #2713Re: Exceptions in destructors
From: Herb Sutter
Date: Sat, 25 Nov 1995 19:20
Date: Sat, 25 Nov 1995 19:20
68 lines
3708 bytes
3708 bytes
In article <494oog$hmf@gabi.gabi-soft.fr>,
kanze@gabi-soft.fr (J. Kanze) wrote:
>Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
>|> schuenem@informatik.tu-muenchen.de (Ulf Schuenemann) writes:
>|> >How about saying that dtors have an empty exception-specification
>|> >(either by default or always) ?
>
>|> How does that help?
I think he wants unexpected() to be called, rather than an inelegant
terminate(), when a dtor throws during unwinding.
>|> >Then there are 3 cases possible:
>|> >- The dtor causes no eception.
>|> >- The dtor catches all exceptions and continues - save,
>|> > but what happens to client-provided exception handling ?
>|> >- The dtor does not handle an exception that happend to be
>|> > be raised - unexpected() is called.
>
>|> Yes, and what if the programmer has defined unexpected()
>|> to rethrow the exception? (In most circumstances, doing so
>|> is probably a much better idea than just crashing via
>|> a call to abort().)
>
>1. How can it know what the exception was to rethrow it? Is a throw
>without an argument legal here? (I don't think so, but I'm not sure.)
I was about to say that it must be legal -- this is precisely what Cline and
Lomow suggest in their FAQ book (FAQ #271). However:
>2. This behavior doesn't seem conform to the required behavior in
>18.6.1.2. I believe that when a user provided routine violates required
>behavior, undefined behavior results.
[Note: 18.6.1.2 in the April draft is now 18.6.2.2 in the Sept WP.]
It seems you're right, since the unexpected_handler isn't supposed to throw
the same (unexpected) exception again. Relevant section follows (from the
Sept WP; the April draft looks identical):
---8<---8<----------------------------------------------------------------
Required behavior:
an unexpected_handler shall either throw an exception or terminate
execution of the program without returning to the caller. An unexΒ
pected_handler may perform any of the following:
--throw an exception that satisfies the exception specification;
--throw a bad_exception exception;
--call terminate();
--call either abort() or exit();
Default behavior:
The implementation's default unexpected_handler calls terminate().
---8<---8<----------------------------------------------------------------
Is disallowing a rethrow deliberate, or something that could be relaxed to
allow rethrowing as Cline and Lomow suggest?
Herb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter 2228 Urwin, Ste 102 voice (416) 618-0184
Connected Object Solutions Oakville ON Canada L6L 2T2 fax (905) 847-6019
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<495ls8$17o@steel.interlog.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<Pine.SGI.3.91-heb-2.02.951114164854.2393A-100000@arava> <48s8fa$aq@sunsystem5.informatik.tu-muenchen.de> <9532523.1824@mulga.cs.mu.OZ.AU> <494oog$hmf@gabi.gabi-soft.fr>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: herbs@interlog.com (Herb Sutter) Newsgroups: comp.std.c++ Subject: Re: Exceptions in destructors Date: 25 Nov 1995 19:20:39 GMT Organization: Connected Object Solutions (div of Daystar Software Systems Design Inc.) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <495ls8$17o@steel.interlog.com> References: <Pine.SGI.3.91-heb-2.02.951114164854.2393A-100000@arava> <48s8fa$aq@sunsystem5.informatik.tu-muenchen.de> <9532523.1824@mulga.cs.mu.OZ.AU> <494oog$hmf@gabi.gabi-soft.fr> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: herbs.interlog.com X-Newsreader: News Xpress Version 1.0 Beta #4 Content-Length: 2680 Originator: clamage@taumet