(ref.doc)sdm 290992

Next bs 110593 Prev: js 020992 Up: Usenet

Newsgroups: comp.std.c++
From: [email protected] (Scott Meyers)
Subject: Exception Specifications
Organization: Brown University Department of Computer Science
Date: Tue, 29 Sep 1992 20:16:03 GMT

The more I think about it, the more I'm convinced that the uses for
exception specifications are astonishingly restricted.  As I see it, you
can't reliably put an exception specification on a function f if any of the
following are true:

    1.  A call to f might directly or indirectly lead to a call to g where
        g lacks an exception specification.  A special case of this is
        where g is a function written in another language, e.g., anything
        in the standard C library.  Recall that functions without exception
        specifications may throw anything.

    2.  f is a template function.  In this case, f must be instantiated
        using some unknown type T, and it is highly likely that f will
        invoke some T-specific function (e.g. member function of class T).
        However, there is no way to know what the exception specifications
        are on the T-specific functions.

    3.  f is a virtual function, because f may be redefined in a subclass
        by some function f' that contains an incompatible exception
        specification.  Recall that an exception specification is not part
        of a function's type.

The ARM refers to an exception specification as a "promise" (ARM 15.6.2c),
but the above points make clear that this promise can't be given very
often, or at least can't be relied upon very often.  Similarly, the
discussion of why exception specifications are so lax is discussed in ARM
15.5c.  The ARM also implies that special-purpose static analyzers would be
required to do much of anything with exception specifications, especially
in the presence of separate compilation.  (For example, if f contains an
exception specification and calls virtual function g which also contains an
exception specification, no warning can be issued if g is redefined by an
incompatible g' in a derived class that is contained in a separate
compilation unit.)

All of which leads me to believe that exception specifications are not
really designed for the "general use" suggested in the last paragraph of
commentary in ARM 15.5c.  That being the case, I'm tempted to suggest they
be removed from the language.  For the specialized applications that can
make use of them, an Anna-like annotation language seems more appropriate
than actual language support within C++.

Comments?

Scott


-------------------------------------------------------------------------------
What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."



automatically generated by info2www version 1.2.2.8