(ref.doc)rmartin 030294
Next daniels 040294
Prev: stroyan 290194
Up: Usenet
Newsgroups: comp.std.c++
From: [email protected] (Robert Martin)
Subject: Re: Exceptions: enforcement of throw() signatures?
Date: Thu, 3 Feb 1994 17:48:56 GMT
[email protected] (Ian Cameron Smith) writes:
>There's been a lot said in the recent exceptions debate about
>exception signatures; eg. "int fred() throw(FredDead);"
>guarantees only to throw the exception FredDead.
>My question is, when is this enforced: compile-time or run-time?
>The ARM says run-time, and goes into great detail as to why this
>decision was made; but I've seen someone state that he believes
>this decision to have been altered to require compile-time
>checking. Does anyone know the current state of play?
I don't know the current state of play, but I have an opinion:
The following ought to be compiler errors.
void f() throw() {throw x;}
void g() throw() {void f() throw (X); f();}
void g() throw(X) {void f() throw (Y); f();} // Y not derivative X
The following ought to be warnings.
void g() throw() {void f(); f();} // grandfather old code.
void g() throw(X) {void f(); f();} // grandfather.
Of course this can get complicated. For example, this should
not be an error:
void f throw(X)
{
void g() throw (Y);
try { g(); } catch(Y) {} Y will not get thrown out of X.
}
To do this right the compiler must do a complete static analysis of
the code to prove no undeclared exception that gets thrown within the
function can escape from the function.
Hmmmm.......Tricky.
automatically generated by info2www version 1.2.2.8