Topic: Exception-specifications


Author: kanze@us-es.sel.de (James Kanze)
Date: 18 May 93 16:57:26
Raw View
In article <1993May15.163658.16683@ucc.su.OZ.AU>
maxtal@physics.su.OZ.AU (John Max Skaller) writes:

|> In article <1sv15g$c43@cville-srv.wam.umd.edu> krc@wam.umd.edu (Kevin R. Coombes) writes:
|> >The desciption of exceptions in the ARM allows functions to declare
|> >exception-specifications that limit the kinds of exceptions it will
|> >throw. However, unlike the return type, the exception specification
|> >is not part of the function's type. Does that make the following code
|> >legal?

This is still being discussed by the standards committee.  There are a
number of people on the committee who what the exception
specifications to be part of the functions type.

If this position wins out, the code which was given will be illegal,
and the error should be caught by the compiler.
--
James Kanze                             email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung




Author: krc@wam.umd.edu (Kevin R. Coombes)
Date: 14 May 1993 02:46:08 GMT
Raw View
The desciption of exceptions in the ARM allows functions to declare
exception-specifications that limit the kinds of exceptions it will
throw. However, unlike the return type, the exception specification
is not part of the function's type. Does that make the following code
legal?

class X {};
class Y {};

typedef void (*PVV)(void);

void f(void) throw(X)
{
     if (I_feel_like_it) throw X();
}

PVV liar = &f;

void g(PVV fptr) throw(Y)
{
     (*fptr)();
}

int main(void)
{
    g(liar);
}

Doesn't that mean that exception specifications are useless in code
that uses function pointers?

Kevin Coombes <krc@math.umd.edu>





Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sat, 15 May 1993 16:36:58 GMT
Raw View
In article <1sv15g$c43@cville-srv.wam.umd.edu> krc@wam.umd.edu (Kevin R. Coombes) writes:
>The desciption of exceptions in the ARM allows functions to declare
>exception-specifications that limit the kinds of exceptions it will
>throw. However, unlike the return type, the exception specification
>is not part of the function's type. Does that make the following code
>legal?
>
>class X {};
>class Y {};
>
>typedef void (*PVV)(void);
>
>void f(void) throw(X)
>{
>     if (I_feel_like_it) throw X();
>}
>
>PVV liar = &f;
>
>void g(PVV fptr) throw(Y)
>{
>     (*fptr)();
>}

 After the call here causes 'X' to be thrown, g catches
the X and calls 'unepxected()'.

>
>int main(void)
>{
>    g(liar);
>}
>
>Doesn't that mean that exception specifications are useless in code
>that uses function pointers?

 No. It means that exception specifications have nothing
to do with the interface of a function really. They make no
hard promises, they're just macros such that

 f() throw (X) { <body> }

expands to

 f() {
  try{ <body> }
  catch(X) { throw; }
  catch(...) { unexpected(); undefined(); }
 }

Unexpected itself can throw an exception ... anything it wants.
(As far as I know)

The only good reason for keeping them in the interface is
documentation. (and debugging?)

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA