Article View: comp.std.c++
Article #1510Re: Uncaught exceptions
From: David Chase
Date: Mon, 31 Jul 1995 15:03
Date: Mon, 31 Jul 1995 15:03
70 lines
3009 bytes
3009 bytes
Etay Bogner <ebogner@ird.scitex.com> writes:
> I'm getting into this debate in the middle :-)
> someone wrote :
> > > I cannot see any logical argument why one of
> > > a) unwinding the whole stack or
> > > b) just terminating without unwinding it
> > > should be prefered by this principle.
> The C++ commitee left the issue open because they wanted to
> continue to support the "dump core" debugging method.
> On the other hand, some operating systems do NOT support this
> debugging feature ( Mac's and PC's for example ) so the
> implemenatation can choose.
Unless the draft standard specifies that a call to
"terminate" may ONLY be used for debugging purposes, it is
both legal and likely for it to do something else, such as
printing a message before exiting.
> So, they couldn't enforce any method ( a or b ).
Unless the standard is worded in such a way as to disallow
the function passed to "set_terminate" below, I believe I
have here an example of a program that could be used to
detect such a difference in implementation. Hence, one
choice or another code be enforced (I have encoded my
preferences into this test program's choice of PASS and
FAIL).
---------------------------------------------------------------
#include <stdio.h>
typedef void (*PFV)();
extern PFV set_unexpected(PFV);
int flag = 0;
struct C { C() {}; ~C() {flag = 1;} };
void f() {
C c;
throw(1);
}
void check_conformance() {
/* If flag set, destructor for c (in f, above) has already run. */
printf(flag ? "FAIL\n" : "PASS\n");
exit(1); /* Draft says: "cannot return", last I checked. */
}
main() {
(void) set_unexpected(check_conformance);
f();
}
---------------------------------------------------------------
P.S. Fergus Henderson pointed out a typo (fortunately, an
obvious one) in the division code in my previous contribution
to this thread. The line
az = udiv(x,y)
is wrong, and should read instead
az = udiv(ax,ay)
Note also, that the corresponding code for remainder takes
the sign (in the conversion from absolute values) from the
dividend alone. Note further that simple shifts and masks
do not suffice for constant division and remainder
operations, but compilers deal with this (efficiently) every
day. Gcc is one widely available example of a compiler that
should get this right, and Sun's compilers are another.
David
Technical Details
Message-ID:
<3virb9$89p@wcap.centerline.com>Path:
arc1-ca.pugleaf.net!wcap.centerline.com!vajra!chaseReferences:
<smeyersDBLDnH.1z7@netcom.com> <3u0o82$gg4@wcap.centerline.com> <3u7e1h$s5@engnews2.Eng.Sun.COM> <3ua4bq$im4@wcap.centerline.com> <3v2vj6$kha@metro.ucc.su.OZ.AU> <3vb50v$rk5@wcap.centerline.com> <3vdt05$inn@lyman.pppl.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wcap.centerline.com!vajra!chase From: chase@centerline.com (David Chase) Newsgroups: comp.std.c++ Subject: Re: Uncaught exceptions Date: 31 Jul 1995 15:03:05 GMT Organization: CenterLine Software Sender: chase@vajra (David Chase) Distribution: world Message-ID: <3virb9$89p@wcap.centerline.com> References: <smeyersDBLDnH.1z7@netcom.com> <3u0o82$gg4@wcap.centerline.com> <3u7e1h$s5@engnews2.Eng.Sun.COM> <3ua4bq$im4@wcap.centerline.com> <3v2vj6$kha@metro.ucc.su.OZ.AU> <3vb50v$rk5@wcap.centerline.com> <3vdt05$inn@lyman.pppl.gov> NNTP-Posting-Host: vajra